Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

SQL Server asp.net datetime issue

Options
  • 11-01-2009 8:38pm
    #1
    Closed Accounts Posts: 317 ✭✭


    Hi All,

    I'm hoping this is an easy to cure but I'm stuck. I'm using lefts and rights and lens to sort it out which is just awful.

    I'm using VWD 2008 and SQL 2005 Ent. Edition.
    I have a datetime field in the database and I have a datasource in asp.net (vb.net) which I'm passing in a parameter for the datetime field to spit out a report.

    The User selects a date on the calendar, so for instance he chooses the 9th January.
    I have this coming out to a text field just so I can see what's happening. Anway, he chooses the 9th and out comes 2009-01-9.
    However, the only way my report will come out is if the date is 2009-01-09.
    So I'm currently doing a check on the lenght and if it's not the right lenght to add a "0" in for the day part. SAD, I know!

    Any help would be fantastic.

    Cheers


Comments

  • Registered Users Posts: 2,791 ✭✭✭John_Mc


    tiptap wrote: »
    Hi All,

    I'm hoping this is an easy to cure but I'm stuck. I'm using lefts and rights and lens to sort it out which is just awful.

    I'm using VWD 2008 and SQL 2005 Ent. Edition.
    I have a datetime field in the database and I have a datasource in asp.net (vb.net) which I'm passing in a parameter for the datetime field to spit out a report.

    The User selects a date on the calendar, so for instance he chooses the 9th January.
    I have this coming out to a text field just so I can see what's happening. Anway, he chooses the 9th and out comes 2009-01-9.
    However, the only way my report will come out is if the date is 2009-01-09.
    So I'm currently doing a check on the lenght and if it's not the right lenght to add a "0" in for the day part. SAD, I know!

    Any help would be fantastic.

    Cheers

    If you're using C#, then you can use the DateTime library functions to format it into the required date format. Most likely the Universal format if you're inserting into a DB.

    http://msdn.microsoft.com/en-us/library/system.datetime_methods.aspx


  • Closed Accounts Posts: 317 ✭✭tiptap


    Many Thanks John,
    The ToShortDateString worked for me.
    Thanks again


  • Registered Users Posts: 2,791 ✭✭✭John_Mc


    tiptap wrote: »
    Many Thanks John,
    The ToShortDateString worked for me.
    Thanks again

    No problem, glad it worked! :)


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    If you are using the Ajax ToolKit calender extender (which is dead handy) there is a format string that you can use that will allow you to format the date however you like


Advertisement