question

dougfast avatar image
dougfast asked

Substring and adding dates

All and Anyone: Happy holidays! This one is throwing me for a loop. I can do Select SUBSTRING('-05:00',2,5) Result: 05:00 I can do: Select Cast(SUBSTRING('-05:00',2,5) as Datetime) Result: 1900-01-01 05:00:00:000 But I can not do Select Cast(05:00 as Datetime). Result: Incorrect syntax near ':' Why? The substring part is a column I may be bringing back, however in some cases I need to hard code it. Is there no way to add or subtract 5 hours or 8:30 hours form a datetime? Long Story: I have three columns Date like this '1101215' -- Dec 15 2010 Time like this '300' -- 3 AM Local_Zone '-05:00' -- 5 hours behind UTC I need to get the time and date into a workable format (That is solved) now how do I take the -05:00 and add 5 hours to get UTC time (The Local Zone could be + or - and could be in 1/2 hours)? Thanks for looking and taking the time to help. :) Doug
datetime
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
David Wimbush avatar image
David Wimbush answered
Hi Doug, You need to put single quotes around the 05:00 because it's a string representation of the datetime.
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

dougfast avatar image dougfast commented ·
David, Right on the money. I thought I had mistyped the post, but no that's how I did it on the program. Well there is my stupid question for the day. Thanks a million. Doug
1 Like 1 ·
ThomasRushton avatar image ThomasRushton ♦♦ commented ·
There are no stupid questions... ...but there are a lot of inquisitive idiots. ;-)
1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.