May 27, 2008 at 2:06 pm
I have three date columns (birthmonth,birthday and birthyear). I want to combine these into one column 'Date of Birth' mm/dd/yyyy. Any help would be appreciated. Thank you
May 27, 2008 at 2:42 pm
The following should do the trick:
select convert(datetime, convert(varchar(4), birthyear) + '-' + convert(varchar(2), birthmonth) + '-' + convert(varchar(2), birthday))
Matt.
May 27, 2008 at 3:08 pm
Hi,
here's a possible solution:
[font="Courier New"]if object_id('TabDate') is not null
drop table TabDate
go
create table TabDate
(birthmonth int,
birthday int,
birthyear int)
go
insert into TabDate(birthmonth, birthday, birthyear) values (06, 19, 1975)
go
select
*,
dateadd(dd, birthday-1, dateadd(mm, birthmonth-1, dateadd(yyyy, (birthyear-1900), 0)))
from TabDate
go
if object_id('TabDate') is not null
drop table TabDate[/font]
Sergio
May 27, 2008 at 3:33 pm
select
[Date of Birth] = dateadd(month,(12*BirthYear)-22801+BirthMonth,BirthDay-1)
from
(
-- Test data
select
BirthYear= 1975,
BirthMonth= 12,
BirthDay= 30
) a
Results:
Date of Birth
------------------------
1975-12-30 00:00:00.000
(1 row(s) affected)
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply