Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to convert Integer value to Datetime value?

How to convert Integer value to Datetime value?

Scheduled Pinned Locked Moved C#
databasehelptutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bigeyed
    wrote on last edited by
    #1

    Hi.. I get 5 int values For instance, they will look like the below... int a = 2006; //year int b = 3; //month int c = 5; //day int d = 1; //hour int e = 3; //min int f = 2; //second but I want to put them in DB looks like "20060305010302" which means.. year has to be 4 digit, month has to be 2digit, day has to be 2digit..and so on... so if I get the month data number 5, then I have to be able to convert number to 05 (because the DB column character is set for "yyyy:MM:dd:HH:mm:ss". can I do this in one shot?? I can't think of anything good... what i'm thinking is that comparing the length and if the length is shorter than 2 then, put the "0" in front of the number.... -_-... please help... thanks

    C 1 Reply Last reply
    0
    • B bigeyed

      Hi.. I get 5 int values For instance, they will look like the below... int a = 2006; //year int b = 3; //month int c = 5; //day int d = 1; //hour int e = 3; //min int f = 2; //second but I want to put them in DB looks like "20060305010302" which means.. year has to be 4 digit, month has to be 2digit, day has to be 2digit..and so on... so if I get the month data number 5, then I have to be able to convert number to 05 (because the DB column character is set for "yyyy:MM:dd:HH:mm:ss". can I do this in one shot?? I can't think of anything good... what i'm thinking is that comparing the length and if the length is shorter than 2 then, put the "0" in front of the number.... -_-... please help... thanks

      C Offline
      C Offline
      chrismerrill
      wrote on last edited by
      #2

      You can create a DateTime object and then use a Custom DateTime Format String. For Example, this generates the output you want: DateTime d = new DateTime (2006,3,5,1,3,2); d.ToString ("yyyyMMddhhmmss"); MSDN Custom DateTime Format Strings Hope this Helps, Chris

      G 1 Reply Last reply
      0
      • C chrismerrill

        You can create a DateTime object and then use a Custom DateTime Format String. For Example, this generates the output you want: DateTime d = new DateTime (2006,3,5,1,3,2); d.ToString ("yyyyMMddhhmmss"); MSDN Custom DateTime Format Strings Hope this Helps, Chris

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        Slight correction to the format string; "hh" gives hours in the range 1-12, use "HH" to get hours in the range 0-23: DateTime d = new DateTime (2006,3,5,1,3,2); d.ToString("yyyyMMddHHmmss");

        --- b { font-weight: normal; }

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups