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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Validated a date

Author  Topic 

shifis
Posting Yak Master

157 Posts

Posted - 2009-02-20 : 14:51:17
Hi
I have to validate a day that could be in the next formats, to see if is right:

d/m/yyyy
dd/m/yyyy
d/mm/yyyy
dd/mm/yyyy

How can I do that?
Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-02-20 : 14:52:52
You could use IsDate function to see if it is a valid date. You could also try converting/casting it to datetime.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-02-20 : 23:35:23
See this link i would be helpfule for u

http://www.sql-server-helper.com/tips/date-formats.aspx
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-02-21 : 01:38:25
quote:
Originally posted by shifis

Hi
I have to validate a day that could be in the next formats, to see if is right:

d/m/yyyy
dd/m/yyyy
d/mm/yyyy
dd/mm/yyyy

How can I do that?
Thanks



1 Always use proper DATETIME datatype
2 Express the dates in universal format YYYYMMDD HH:MM:SS
3 To see if they are valid dates, assuming you express them in dmy format

SET dateformat dmy
select isdate(ypur_date)


Madhivanan

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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-21 : 01:50:00
quote:
Originally posted by shifis

Hi
I have to validate a day that could be in the next formats, to see if is right:

d/m/yyyy
dd/m/yyyy
d/mm/yyyy
dd/mm/yyyy

How can I do that?
Thanks




isdate(col)=1
and len(col)>8
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-02-21 : 02:06:33
quote:
Originally posted by visakh16

quote:
Originally posted by shifis

Hi
I have to validate a day that could be in the next formats, to see if is right:

d/m/yyyy
dd/m/yyyy
d/mm/yyyy
dd/mm/yyyy

How can I do that?
Thanks




isdate(col)=1
and len(col)>8



Wont work without SET dateformat dmy

Madhivanan

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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-21 : 02:23:54
quote:
Originally posted by madhivanan

quote:
Originally posted by visakh16

quote:
Originally posted by shifis

Hi
I have to validate a day that could be in the next formats, to see if is right:

d/m/yyyy
dd/m/yyyy
d/mm/yyyy
dd/mm/yyyy

How can I do that?
Thanks




isdate(col)=1
and len(col)>8



Wont work without SET dateformat dmy

Madhivanan

Failing to plan is Planning to fail


yup thats true
Go to Top of Page
   

- Advertisement -