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 2000 Forums
 SQL Server Development (2000)
 problem in date string

Author  Topic 

abhi143
Starting Member

32 Posts

Posted - 2006-03-01 : 09:03:46
hi all of u...

i want to write stored procedure, in which there will be two string.

i.e 15/06/2005 and 15/10/2005(mm/dd/yyyy) format.

Note that it is not Date data type..

now i want to compare that if Date1 is greater than Greater Date2
then -----
else ----
end

thanks

abhi

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-03-01 : 09:09:33
convert the strings to datetime type
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-03-01 : 09:11:01
Why do you want to use varchar datatype for Dates?
Use DateTime datatype to avoid unnecessary conversions. Also dont format to local settings. Use universal format yyyy-mm-dd so that your date is 2005-06-15 and not 15/06/2005

Use Datetime parameters in stored procedure and compare them as

If @date1>@date2 then
---
else
---

Madhivanan

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

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-03-01 : 09:26:19
[code]Declare @d1 varchar(30), @d2 varchar(30)
Set @d1 = '15/06/2005'
Set @d2 = '15/10/2005'

Print convert(datetime,@d1,103)
Print convert(datetime,@d2,103)

if convert(datetime,@d1,103) < convert(datetime,@d2,103)
Begin
Print ' d1 > d2 '
End
else
Begin
Print ' d1 < d2 '
End[/code]
Go to Top of Page
   

- Advertisement -