How to convert Integer value to Datetime value?
-
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
-
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
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
-
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