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)
 Returning a date from an int

Author  Topic 

dcummiskey
Starting Member

26 Posts

Posted - 2004-09-22 : 19:06:52
Hi -
I have a field in the db that stores an int (1-31)...this number being the day of the month. I'm trying to have a date returned for this number...for instance: 9/21/2004. How do i combine the current month with the column and the current year?

Thanks in advance,
Dan

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2004-09-22 : 19:35:34
A bit long-winded, but here goes:
Convert(DateTime, Convert(varchar, Month(GetDate())) + '/' + Convert(varchar, <yourField>) + '/' + Convert(varchar, Year(GetDate())))
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-09-22 : 20:52:08
convert(varchar(6),getdate(),112) + right('0' + convert(varchar(2),@int),2)

yyyymmdd can always be used as a date without convertion.
With timmy's you should give a style on the datetime convert..

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

dcummiskey
Starting Member

26 Posts

Posted - 2004-10-05 : 19:57:56
Thanks =) sorry for the late reply...was just able to get back to this project.
Go to Top of Page
   

- Advertisement -