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
 seconds2date (Resolved)

Author  Topic 

aakcse
Aged Yak Warrior

570 Posts

Posted - 2012-08-10 : 14:27:20
Hi I have data in sec I want to convert it to date

lastupdate col has value as which is in sec as per below note from IBM
1337027545
1337207734

I want to convert it to this format 01 Jan 2010


lastupdate Specifies the time (in seconds) since the epoch (00:00:00 GMT, January 1, 1970) when the password was last changed. If password aging (the minage attribute or the maxage attribute) is in effect, the lastupdate attribute forces a password change when the time limit expires. (See the /etc/security/user file for information on password aging.) The passwd and pwdadm commands normally set this attribute when a password is changed. The value is a decimal integer that can be converted to a text string using the ctime subroutine.

-Neil

chadmat
The Chadinator

1974 Posts

Posted - 2012-08-10 : 14:39:51

select DATEADD(ss, 1337027545, '1/1/70 00:00:00' )

-Chad
Go to Top of Page

aakcse
Aged Yak Warrior

570 Posts

Posted - 2012-08-10 : 14:47:23
thanks :)


-Neil
Go to Top of Page

aakcse
Aged Yak Warrior

570 Posts

Posted - 2012-08-10 : 14:52:39
Want to display it in the below format
01 Jan 2010


isnull(DATEADD(SS,cast(sp.LastUpdate as INT),'1/1/70 00:00:00'),'') as [Last Update]


is displaying it as '2012-05-16 22:49:05.000'

-Neil
Go to Top of Page

chadmat
The Chadinator

1974 Posts

Posted - 2012-08-10 : 14:59:46
Convert(varchar(30),isnull(DATEADD(SS,cast(sp.LastUpdate as INT),'1/1/70 00:00:00'),''), 13) as [Last Update]


-Chad
Go to Top of Page

aakcse
Aged Yak Warrior

570 Posts

Posted - 2012-08-10 : 15:01:47
got it

SELECT CONVERT(VARCHAR(11), SYSDATETIME(), 106) AS [DD MON YYYY]

-Neil
Go to Top of Page

aakcse
Aged Yak Warrior

570 Posts

Posted - 2012-08-10 : 15:02:53
thanks Chadmat :)

-Neil
Go to Top of Page

chadmat
The Chadinator

1974 Posts

Posted - 2012-08-10 : 15:52:41
quote:
Originally posted by aakcse

thanks Chadmat :)

-Neil



Welcome!
Go to Top of Page
   

- Advertisement -