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 Administration
 current date time format

Author  Topic 

java148
Yak Posting Veteran

63 Posts

Posted - 2011-10-26 : 21:11:58
do we have an easy way to get current date time ? for example, 10/26 2011 23:12:45, it should give me '20111026231245'

another question, how to select current time in milliseconds ? like System.currentTimeMillis() in java.

Thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-10-26 : 21:55:48
[code]
select currentDateTime = replace(replace(replace(convert(varchar(19), getdate(), 121), '-', ''), ' ', ''), ':', ''),
currentTimeMillis = convert(bigint, datediff(day, '1970-01-01', getdate())) * 24 * 60 * 60 * 1000
+ datediff(millisecond, dateadd(day, datediff(day, 0, getdate()), 0), getdate())
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

java148
Yak Posting Veteran

63 Posts

Posted - 2011-10-26 : 22:29:30
works, add it to my master db.

thanks.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-10-26 : 22:42:29
welcome


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -