locked
DateTime to yyyymmdd

    Question

  • Hi,
    I'm extracting a Datetime value from a Datepicker.Date & I need for it to be in 'yyyymmdd' string in order to compare it to pass it to a SQL Stored procedure & use it in a Datediff function.

    How can I do this?

    This is what I'm doing:
    string date = dateTimePicker1.Value.Date.ToShortDateString();  
     
    // this gives me a string 'dd/mm/yyyy' but need 'yyyymmdd' without backslash 

    Any ideas would be much appreciated.

    Many thanks

    @nt
    Tuesday, August 26, 2008 4:09 AM

Answers

  • Use this:

    dateTimePicker1.Value.ToString("yyyyMMdd"

    It's important to use MM (for month) and not mm (for minutes) - case matters.

    Document my code? Why do you think it's called "code"?
    • Marked as answer by A n t Wednesday, August 27, 2008 12:59 AM
    Tuesday, August 26, 2008 5:57 AM