Tech Off Post

Single Post Permalink

View Thread: C# Sting converstion
  • User profile image

    figuerres said:
    W3bbo said:

    Yeah I wonder if the OP meant:


    an International Date ?

    or possibly some long int format like 12252009 ?


    If its a date or time value stored in an integer representation of something like ticks or miliseconds then it's trivial, just multiply and cast to long to get ticks, then use DateTime's ticks constructor.


    If it's something like 25122009 then the OP has my sympathy, how does something like that happen?


    Well, if it is like 25122009 then convert it to a digit array (might as well just convert to a string) then extract the bits you need, then convert to int or datetime:


    String input = 25122009.ToString();

    String dayStr = input.Substring(0,2);

    String monStr = input.Substring(2,2);

    String yerStr = input.Substring(4,4);


    DateTime date = new DateTime( int.Parse( dayStr ), int.Parse(monStr), int.Parse(yerStr) );