i have 2 fields that i want to concatenate and then convert it's date format. one field is a smalldatetime, the other is a varchar:
u_Departure_Time = varchar(5), ex data is 05:30 or 16:30
EffFrom = smalldatetime, ex data is 09/01/2003
trying to do something like this:
CONVERT(datetime,(dateadd(dd, value, EffFrom)+' '+u_Departure_Time),'mm/dd/yyyy hh:mi:ms AM')
i need to take the varchar 24hr time from u_Departure_Time, concatenate it to EffFrom and make it 12hr format. In the above examples I'd like to obtain:
9/1/2003 5:30:00 AM
9/1/2003 4:30:00 PM
it seems basic, but i'm an oracle guy, just started using sql server.
thanks!select cast(convert(char(10), EffFrom, 101) + ' ' + u_Departure_Time as datetime)|||Try this one:
declare @.date smalldatetime,@.time varchar(10)
set @.date='09/17/2003'
set @.time='16:30'
select cast(@.date+' '+@.time as datetime)|||Originally posted by ms_sql_dba
select cast(convert(char(10), EffFrom, 101) + ' ' + u_Departure_Time as datetime)
cool, i tried this:
,cast(convert(char(10), EffFrom, 101) + ' ' + u_Departure_Time as smalldatetime)
but it's in 24hr time,
sample: 2003-08-01 19:25:00
i need it to match another tables format of dd/mm/yyyy h:mm:ss AM/PM
like: 2003-08-01 7:25:00 PM
this is really a newbie question, but what does the '101' signify?|||101 converts 2003-09-01 to 09/01/2003 format so that you can att time portion to it before converting it back to datetime.
Sunday, February 19, 2012
date conversion question
Labels:
concatenate,
conversion,
convert,
database,
date,
field,
fields,
format,
microsoft,
mysql,
oracle,
server,
smalldatetime,
sql
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment