Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the equivalent of php time() in mssql?

Tags:

php

sql-server

For example if I execute the code below under my Windows 7-I have PHP running under windows 7/IIS.

echo time() I will get this 1304972050

How can I get the same result in MSSQL?

like image 765
RRG Avatar asked May 09 '11 20:05

RRG


People also ask

How to get timestamp in SQL Server?

The CURRENT_TIMESTAMP function returns the current date and time, in a 'YYYY-MM-DD hh:mm:ss. mmm' format. Tip: Also look at the GETDATE() function.

Does PHP work with MS SQL?

The Microsoft Drivers for PHP for SQL Server enable integration with SQL Server for PHP applications. The drivers are PHP extensions that allow the reading and writing of SQL Server data from within PHP scripts.

How do I find the date and time of a SQL Server server?

SQL Server GETDATE() Function The GETDATE() function returns the current database system date and time, in a 'YYYY-MM-DD hh:mm:ss. mmm' format. Tip: Also look at the CURRENT_TIMESTAMP function.

How to get date and time from timestamp in SQL?

In SQL, CURRENT_TIMESTAMP is used to extract the current date and time. It takes no argument and returns the datetime value.


1 Answers

SELECT DATEDIFF(ss, '1/1/1970 05:00:00', GETUTCDATE())

Should do.

UPDATED per comment.

like image 51
David Fells Avatar answered Oct 07 '22 07:10

David Fells