Date Manipulation in Php - Page 4

Converting existing dates into Unix timestamps

Often you may have to work with data that is already in some sort of date and time
format. I opened a clients Microsoft Access database now and found that the dates
are all stored in the format YYYY/MM/DD, so inserting the current date would give
me 2000/05/27. The mktime() function can take the values of parts of a date and
turn them into a Unix timestamp.

From the left you provide the hour, minute, second, month, day and year. The last argument
specifies whether you are in daylight savings time or not. It is optional and so to keep
things simple we will leave it out.

The script will look something like this:

<?php

echo mktime( 0,0,0,5,27,2000 );

?>

I've put in zeros for the hour, minute and seconds since we don't know them and you have to
put something in there. Putting in zeros will give us midnight, which is fine. Of course
you're probably pointing out right now that I've cheated and gone and put the numbers in there
myself, which is true, so let's do it again, this time by making the script work out what to put into where:

<?php

$access_date = '2000/05/27';

// The explode() function splits a string by another string. In this case $access_date is
// split on the /