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
 date validations in sql server

Author  Topic 

onkabetse
Starting Member

5 Posts

Posted - 2011-04-20 : 14:02:52
please help me on how to validate a field orderdate to accept dates that is less than current date,

I tried the syntax orderdate<GETDATE() but failed.

I also tried the statement: select [table name]
where orderdate = (today's date & time)
but also failed. please help me,I am new to sql programming

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-04-20 : 14:05:21
Please give table structure, sample data and wanted result in relation to sample data.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2011-04-21 : 00:14:24
try using check constraint on orderdate column...
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-04-21 : 00:31:33
quote:
Originally posted by onkabetse
I tried the syntax orderdate<GETDATE() but failed.

I also tried the statement: select [table name]
where orderdate = (today's date & time)
but also failed. please help me,I am new to sql programming



did you try this ?

SELECT *
FROM [table name]
WHERE orderdate < getdate()


"dates that is less than current date"
If you don't want to include the time

SELECT *
FROM [table name]
WHERE orderdate < dateadd(day, datediff(day, 0, getdate()), 0)




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

Go to Top of Page

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2011-04-21 : 00:37:49
whats your requirement?is it to restrict users to enter data less then provided date or is it your select query where you want display records based on the condition...????
Go to Top of Page
   

- Advertisement -