-3

I'm currently in the process of converting some basic sql scripts from Postgresql to Azure Sql. I'm newbie to sql, but I really can't understand epoch/unix time in Azure SQL / SQL Server. My application is using bigint epoch time as event timestamp and I want to make a housekeep script for the database and for the table where events are stored.

How do you work with epoch time intervals in MS or Azure SQL? What would be the equivalent in Azure SQL to the following query?

SELECT count(*) FROM info_event WHERE event_time < (SELECT cast(EXTRACT(epoch FROM current_timestamp - INTERVAL '1 MONTH') AS bigint) * 1000); 
  • 1
    There are plenty of examples of how to convert a date and time value to a epoch here; what were wrong with those examples? What didn't you understand about them or why don't they work for your scenario? – Thom A Oct 18 '21 at 13:25
  • I can't understand how to work with epoch time interval in MSSQL – guyfromnowhere Oct 18 '21 at 13:41

1 Answers1

0

The solution was.

SELECT * FROM table WHERE epoch_column < (SELECT cast(DATEDIFF(second,'1970-01-01 00:00:00',(DATEADD(month,-1,GETDATE())))AS bigint)* 1000 );

Thanks for the help!