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
 General SQL Server Forums
 New to SQL Server Programming
 Converting UNC time to standard mm/dd/yyyy format?

Author  Topic 

crugerenator
Posting Yak Master

126 Posts

Posted - 2010-03-02 : 17:00:17
I'm trying to convert UNC time to a standard date format. I use DateAdd to convert UNC time to regular time (?, is that what you call it?), after that I'm having trouble getting the date to format correctly. The formatting has to be done in my query instead of in code afterwards (which I would normally do since I've googled this for 20 min already).

Here's what I have:

CONVERT(varchar, DATEADD(ss, changedate,'12/31/1969 20:00:00'), 100)

Output Example:
Sep 16 2005 3:21PM

What I Need:
9/16/2005 3:21PM

Any help is appreciated, these boards always rock.

crugerenator
Posting Yak Master

126 Posts

Posted - 2010-03-02 : 17:12:47
I actually just figured it out. Thanks to anyone who might have been spending time on this...

CONVERT(VARCHAR(10), DATEADD(ss, changedate,'12/31/1969 20:00:00'), 101) + ' ' + RIGHT(CONVERT(VARCHAR, DATEADD(ss, changedate,'12/31/1969 20:00:00'), 100), 7)
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-03-02 : 17:19:02
I just was on my way to post that there isn't a "ready" simple convert for this and you have to do it with concatenating...

But it is fine that you figured it out by yourself


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-03 : 02:21:35
quote:
Originally posted by crugerenator

I actually just figured it out. Thanks to anyone who might have been spending time on this...

CONVERT(VARCHAR(10), DATEADD(ss, changedate,'12/31/1969 20:00:00'), 101) + ' ' + RIGHT(CONVERT(VARCHAR, DATEADD(ss, changedate,'12/31/1969 20:00:00'), 100), 7)


Where do you want to show data?
If you use front end application, do formation there

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -