— SQL Server string to date / datetime conversion – datetime string format sql server — MSSQL string to datetime conversion – convert char to date – convert varchar to date — Subtract 100 from […]
Get latest order on customer
http://stackoverflow.com/questions/121387/fetch-the-row-which-has-the-max-value-for-a-column/123481#123481 I see many people use subqueries or else vendor-specific features to do this, but I often do this kind of query without subqueries in the following way. It uses plain, standard SQL so it […]
Convert to Unix Timestamp
Converting a datetime to unix timestamp is easy, but involves error prone typing the following: @timestamp=DATEDIFF(second,{d ‘1970-01-01’},@datetime) Where @datetime is the datetime value you want to convert. The {d ‘yyyy-mm-dd’} notation is an ODBC escape […]
Convert from datetime to varchar
CONVERT(VARCHAR(12),DATEADD(S, getdate(), ‘1970-01-01’),105) Specification according to https://msdn.microsoft.com/library/ms187928
Convert from Unix timestamp
Select dateadd(S, [unixtime], ‘1970-01-01’) From [Table] Source http://stackoverflow.com/questions/2904256/how-can-i-convert-bigint-unix-timestamp-to-datetime-in-sql-server