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 :)

Bookmark with :
Digg It! DZone StumbleUpon Technorati Reddit Del.icio.us Newsvine Furl Blinklist
posted @ Friday, April 20, 2007 8:43 AM | in SQL Server

Comments

No comments posted yet.

Post Comment

Title *
Name *
Email
Url
Comment *  


Please add 2 and 7 and type the answer here: