PHPBuilder - date_to_timestamp function (and back)

RSS Twitter

date_to_timestamp function (and back)

by: Stephan van der Hulst
March 16, 2001

Version: 1.0

Type: Function

Category: Calendars/Dates

License: GNU General Public License

Description: Two basic functions to convert a mySQL date to a UNIX timestamp and back.

//date_to timestamp accepts a date as parameter. In mySQLformat: yyyy-mm-dd (eg. 2001-03-16)
//edit the delimiter to your convenience.
//returns $timestamp; the timestamp associated with the input.

function date_to_timestamp ($date)
$split_date = split ('-', $date);
$timestamp = gmmktime (0, 0, 0, $split_date[1], $split_date[2], $split_date[0]);
return $timestamp;

//timestamp_to_date accepts a timestamp as parameter.
//returns $date. In mySQLformat; yyyy-mm-dd (eg. 2001-03-16)

function timestamp_to_date ($timestamp)
$date = date ("Y-m-d" , $timestamp);
return $date;

Comment and Contribute

Your comment has been submitted and is pending approval.

Stephan van der Hulst



(Maximum characters: 1200). You have characters left.