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)
 Equivalent in SQL to DateSerial function in access

Author  Topic 

GrantMason
Starting Member

7 Posts

Posted - 2001-12-30 : 19:41:11
Does anyone know if there is an equivalent function or way of returing a date constructing from its parts, year month and day - such as DateSerial in Access?

Thanks in advance.

Grant



smccreadie
Aged Yak Warrior

505 Posts

Posted - 2001-12-30 : 20:10:12
Look up DatePart in Books On Line

Go to Top of Page

GrantMason
Starting Member

7 Posts

Posted - 2001-12-30 : 20:22:18
Thanks for your reply.

But unless I am missing something, which is entirely possible, DatePart returns a part of a date eg. the month as an integer. What I need is for the function to return the date.

For example in access:

DateSerial(2001,12,25) would return '25/12/2001' - this is what I need.

Hopefully that was clearer this time.

Grant

Go to Top of Page

izaltsman
A custom title

1139 Posts

Posted - 2001-12-30 : 21:24:26
CONVERT function will do the trick here.


-- If your year month and date are char/varchar variables or literals:

select CONVERT (datetime, '25'+'/'+'12'+'/'+'2001', 103)

-- If your year month and date are numeric variables or literals:

declare @year int
declare @month int
declare @day int

SELECT @year = 2001, @month = 12, @day = 25
SELECT CONVERT(datetime, cast(@day as varchar)+'/'+cast(@month as varchar)+'/'+cast(@year as varchar), 103)




Go to Top of Page

GrantMason
Starting Member

7 Posts

Posted - 2001-12-31 : 12:31:05
That's great - many thanks and Happy New Year.

Grant

Go to Top of Page
   

- Advertisement -