Groups | Blog | Home
all groups > sql server programming > september 2005 >

sql server programming : convert seconds to datetime


vanitha
9/21/2005 9:50:01 PM
Hi friends,

I want to convert datetime that is stored as seconds to the actual datetime.

Example

Expiredate is stored as seconds since 1/1/1970 (ctime)

Expiredate = 1200373200

convert this to actual datetime

Please help me to solve this. It is very urgent.

thanks
vanitha
R.D
9/21/2005 10:00:02 PM
vanitha try
declare @Expiredate bigint
select @Expiredate = 1200373200
select dateadd(s,@Expiredate ,01/01/1970)
Regards
R.D
[quoted text, click to view]
R.D
9/21/2005 10:03:03 PM
or
declare @Expiredate bigint
declare @Ctime datetime
select @Ctime ='01/01/1970'
select @Expiredate = 1200373200
select dateadd(s,@Expiredate ,@Ctime)

[quoted text, click to view]
vanitha
9/21/2005 10:09:02 PM
Thanks R.D

we shd put date inside the quotes otherwise its giving us wrong solution. I
don't know y.

example

declare @Expiredate bigint
select @Expiredate = 1200373200
select dateadd(s,@Expiredate ,01/01/1970)

result : 1938-01-15 05:00:00.000

declare @Expiredate bigint
select @Expiredate = 1200373200
select dateadd(s,@Expiredate ,'01/01/1970')

result : 2008-01-15 05:00:00.000

thanks
vanitha



[quoted text, click to view]
R.D
9/21/2005 10:25:01 PM
you r right vanitha.
if you dont put inside quotes then it treats it as date out of range in sql
server. so starts from base date of sql server.
Regards
R.D

[quoted text, click to view]
R.D
9/21/2005 10:34:02 PM
vanitha
when you get help from news groups, It is your duty to check it as answer.
This will encourage people to answer more quetions. do read help availbe top
right corner.
Regards
R.D

[quoted text, click to view]
vanitha
9/21/2005 10:49:02 PM
sure R.D.

I used to do it. this time i just replied back.

thnks



[quoted text, click to view]
R.D
9/21/2005 10:49:02 PM
Vanithaji
I was talking generally, not for my post alone. Any way thanks for that.
Regards
R.D


[quoted text, click to view]
Mike Hodgson
9/22/2005 12:00:00 AM
The date should really be expressed in "yyyymmdd hh:nn:ss.000" format as
it is unambiguous regardless of locale. For example:

dateadd(s, @Expiredate, '19700101 00:00:00.000')

or

dateadd(s, @Expiredate, '19700101')

--
*mike hodgson*
blog: http://sqlnerd.blogspot.com



[quoted text, click to view]
Mike Hodgson
9/22/2005 12:00:00 AM
Help in the top right corner? Only if you're using a web-based
newsreader such as
http://www.microsoft.com/technet/community/newsgroups/dgbrowser/en-us/default.mspx?dg=microsoft.public.sqlserver.server&lang=en&cr=US
(Many of us use a real NNTP newsreader, like Mozilla Thunderbird or
Microsoft Outlook Express for example.) ;)

--
*mike hodgson*
blog: http://sqlnerd.blogspot.com



[quoted text, click to view]
AddThis Social Bookmark Button