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)
 Date issues in sqlserver 2000

Author  Topic 

sqldba2k6
Posting Yak Master

176 Posts

Posted - 2007-06-14 : 17:31:54
I have below data in a table

Table1:

MM DD YR
--- -- ----
5 4 2007

I need the below output like.

Date
----------
2006-05-26


Thanks for your help in advance

sqldba2k6
Posting Yak Master

176 Posts

Posted - 2007-06-14 : 17:35:17
Please ignore my previous post

Below is correct one

I have below data in a table

Table1:

MM DD YR
--- -- ----
5 4 2007

I need the below output like.

Date
----------
2007-05-04


Thanks for your help in advance
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-06-14 : 17:44:07
Here are two ways:
DECLARE @T TABLE (MM int, DD int, YR int)
INSERT @T
SELECT 5, 4, 2007


SELECT
CAST(CAST(YR AS VARCHAR) + RIGHT('0' + CAST(MM AS VARCHAR), 2) + RIGHT('0' + CAST(DD AS VARCHAR), 2) AS DATETIME)
,DATEADD(DAY, DD - 1, DATEADD(MONTH, MM - 1,DATEADD(YEAR, YR - 1900, 0)))
FROM @T
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-06-14 : 17:47:44
Keep it simple:

http://weblogs.sqlteam.com/jeffs/archive/2007/01/02/56079.aspx

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

sqldba2k6
Posting Yak Master

176 Posts

Posted - 2007-06-14 : 20:49:09
Thanks a lot
Go to Top of Page

johnsql
Posting Yak Master

161 Posts

Posted - 2007-11-12 : 16:52:27
quote:
Originally posted by sqldba2k6

Please ignore my previous post

Below is correct one

I have below data in a table

Table1:

MM DD YR
--- -- ----
5 4 2007

I need the below output like.

Date
----------
2007-05-04


Thanks for your help in advance



Another way to do

select mm, dd, yr, dateadd(day,dd-1,dateadd(month,mm-1,dateadd (year,yr-1900,0))) as DateInQuestion
from @t
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-11-12 : 17:47:00
SELECT DATEADD(MONTH, YR * 12 - 22801 + MM, DD - 1)




E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -