0

one table of my database in sqlserver have a column with type of int for store dates.

for example fields are: 1105275802 or 1100330268.

I can convert it to datetime in php with this code:

(int)date('U',1100330268);

I want convert this integers to datetime in sqlserver. how can i do?

thanks for any help.

John Carter
  • 53,924
  • 26
  • 111
  • 144
atabrizi
  • 908
  • 1
  • 13
  • 29
  • possible duplicate of [How can I convert bigint (UNIX timestamp) to datetime in SQL Server?](http://stackoverflow.com/questions/2904256/how-can-i-convert-bigint-unix-timestamp-to-datetime-in-sql-server) – John Carter Sep 30 '12 at 07:36

1 Answers1

2

That might be difficult since MS SQL run's on Windows systems and date('U') is "Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)". I suppose you could probably calculate the DateTime, but it could get messed up if you don't account for the timezone change between GMT and your local timezone.

select DateAdd(second, 1100330268, '1970-01-01')
Adam Plocher
  • 13,994
  • 6
  • 46
  • 79
  • +1 Since a UNIX timestamp _is_ based on UTC, you're calculating the UTC time. Not a bad thing, it's pretty easy to convert from UTC to local time compared to doing it the other direction. – Joachim Isaksson Sep 30 '12 at 07:42