Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 stop procedure if date format wrong

Author  Topic 

pmccann1
Posting Yak Master

107 Posts

Posted - 2008-07-28 : 05:34:58
Is there a way to check at the beginning of a stored procedure the format of the date i.e make sure that it is not american date format and if it is do not run the SP.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-28 : 05:40:54
quote:
Originally posted by pmccann1

Is there a way to check at the beginning of a stored procedure the format of the date i.e make sure that it is not american date format and if it is do not run the SP.


What do you want to do if it is of different format?
You should always use DAETTIME datatype and express dates in YYYYMMDD HH:MM:SS format to work for all date settings

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

pmccann1
Posting Yak Master

107 Posts

Posted - 2008-07-28 : 05:47:08
If the date is not in english format i.e dd/mm/yyyy then i want the stored procedure to just stop
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-28 : 05:48:24
How do you know 01/02/2008 is DD/MM/YYYY or MM/DD/YYYY ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-07-28 : 05:48:57
So how would you know what format 12/11/2008 is?



CODO ERGO SUM
Go to Top of Page

pmccann1
Posting Yak Master

107 Posts

Posted - 2008-07-28 : 05:59:46
Thats what i am wanting to know is there a way of making sure the date format is correct on the server for instance getdate() s in the right format. we ahve had a problem where it was not and i would just like to put something in place
Go to Top of Page

VGuyz
Posting Yak Master

121 Posts

Posted - 2008-07-28 : 06:02:56
Check with isdate() function,
or
convert u'r date into american standard.
SELECT CONVERT(VARCHAR(8), GETDATE(), 1) AS [MM/DD/YY]
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-28 : 06:04:09
quote:
Originally posted by pmccann1

Thats what i am wanting to know is there a way of making sure the date format is correct on the server for instance getdate() s in the right format. we ahve had a problem where it was not and i would just like to put something in place


What was your problem?
Can you post the problamatic code?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-28 : 06:05:42
quote:
Originally posted by VGuyz

Check with isdate() function,
or
convert u'r date into american standard.
SELECT CONVERT(VARCHAR(8), GETDATE(), 1) AS [MM/DD/YY]


http://sqlblogcasts.com/blogs/madhivanan/archive/2007/09/24/handle-isdate-with-care.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

pmccann1
Posting Yak Master

107 Posts

Posted - 2008-07-28 : 06:11:53
basically the code was
where end_date <= getdate()

this was run on the 01/02/2008 but some came through because it read the date as 02/01/2008
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-28 : 06:20:51
quote:
Originally posted by pmccann1

basically the code was
where end_date <= getdate()

this was run on the 01/02/2008 but some came through because it read the date as 02/01/2008


What is the datatype of the column?


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

pmccann1
Posting Yak Master

107 Posts

Posted - 2008-07-28 : 06:41:07
datetime but it was the getdate that was wrong because the server was in american
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-28 : 06:47:36
quote:
Originally posted by pmccann1

datetime but it was the getdate that was wrong because the server was in american


It is of datetime column, you dont need to worry
Your query would produce correct result

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2008-07-28 : 07:27:14
Madhivanan is correct - if the column is a datetime column, the query would work fine. If you do have a problem, this isn't it.

Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-28 : 07:49:09
try specifying explicit format of date using

SET DATEFORMAT dmy
Go to Top of Page
   

- Advertisement -