New Years Day Timestamp

Some work I’ve been involved with (see here and here) with UNIX Timestamps threw up another challenge today- getting the timestamp for midnight on January 1st of the current year. This is what I came up with:

SQL (using MySQL 5.5)

mysql> SELECT UNIX_TIMESTAMP(DATE_FORMAT(NOW(),'%Y-01-01 00:00:00'));
| UNIX_TIMESTAMP(DATE_FORMAT(NOW(),'%Y-01-01 00:00:00')) |
|                                             1325376000 |
1 ROW IN SET (0.00 sec)

Excel (using Office 2003)


Visual BASIC (using Visual Studio .NET 2005)

Console.WriteLine(DateAndTime.DateDiff(DateInterval.Second, CDate("1970-01-01 00:00:00"), CDate(Now.Year.ToString + "-01-01 00:00:00")))


Leave a Reply

Your email address will not be published. Required fields are marked *