7

I am trying to get teh current time as a unix timestamp from my MSSQL database.

In Mysql I could say something like:

SELECT id,
            caregiver_id,
            client_id,
            week_no,
            CURTIME() as Synch_Time
FROM dbo.Visits 

But THERE is no CURTIME() function in T-SQL

Does anyone know of a solution?

Thanks

Kevin

Kevin Bradshaw
  • 6,327
  • 13
  • 55
  • 78

3 Answers3

9

You can use getdate() and do some calculations described here. http://mysql.databases.aspfaq.com/how-do-i-convert-a-sql-server-datetime-value-to-a-unix-timestamp.html

Mikael Eriksson
  • 136,425
  • 22
  • 210
  • 281
0

In SQL2012, use can convert to specific date and time types, e.g.

   SELECT
           Time = CONVERT(TIME, GETDATE()),  
           Date = CONVERT(DATE, GETDATE())
Wayne
  • 1
0

getdate() is MSSQL specific, but current_timestamp() is more standard compliant. See similar question: Retrieving date in sql server, CURRENT_TIMESTAMP vs GetDate()

Community
  • 1
  • 1
Brent D
  • 898
  • 5
  • 16