ASP Date and Time to SQL Datetime

  • I'm using the Date() and Time() Functions from Classic ASP (Haven't upgraded this particular site to .NET yet) and passing them into a stored procedure. This gives me a string in this format:

    DECLARE @SubmitDate varchar(30)

    SET @SubmitDate = '10/6/2008_2:37:33 PM'

    I'm trying to convert this into a valid SQL datetime including seconds. Every conversion I've gotten to work thus far has either dropped the seconds, or required crazy string manipulation with multiple replaces and left/right/substrings.

    Anyone know how I can end up with something like: 2008-10-06 02:37:33.000 without ripping the string all apart?

    Thanks,

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. 😉

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]

  • Why do you have an "_" between the date and time? If you pass the string without the underscore and have the stored procedure parameter defined as datetime then it should work with the implicit conversion from string to datetime.

  • Indeed it does. I was using the _ to ensure that nothing wacky happened with the Querystring, but SQL handles the %20 just fine. Thanks Jack.

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. 😉

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply