by matt
20. April 2007 07:43
Heh, a slight addition to my previous post here. Kinda feeling sheepish now.
My code worked frin for about 8 hours or su, until randomly, my client in question decided to switch date formats. I can't really figure out why, but intermittantly, the thing calling my code will send 4/20/2007 or 20/4/2005. This kinda sucks so I have to have another scurry around on google to see what I could find. Basically,
this article by Amol Kulkarni here helped me out alot.
You have to be careful with
XACT_ABORT I think, again - I'm not SQL guru and I'll need to read up on this. It seems fairly similar to VB's 'On Error Resume Next' and as such could be quite dangerous if not handled correclty.
Either way, my lovely SQL code now caters for
dd/mm/yyyy and mm/dd/yyyy looks like this:
Declare @DateTime varchar(50)
Declare @dtmDate datetime
Set @Datetime = '4/20/2007 12:03:56 AM'
Set XACT_ABORT OFF
Select @dtmDate = Convert(varchar, Convert(datetime, @DateTime, 103), 109)
If (@@Error <> 0) Select @dtmDate = Convert(varchar, Convert(datetime, @DateTime, 101), 109)
Set XACT_ABORT ON
Print @dtmDate
Hopefully that's that end of it :)
a4eb099e-f52e-4acf-bee1-0fc7e3f7e0dc|0|.0
Tags:
SQL Server