you are trying to split $timestamp2 (which is 988693200) delimited by "-"
if you want to get back to (yyyy-mm-dd) format you should use another function such as date(). There are several ways to format a timestamp.
mktime only returns time since epoch (in seconds). You already have that information.
To convert back to human readable form, try the date() function.
$viewdate = date("%Y-%m-%d", $timestamp2);
note: If you are using postgres you may want to check out a function called date_part. It can save you tons of date/time nightmares.
twisted wrote:
How do I convert this timestamp back to a date? I'm getting a negative one (-1).
// DISPLAY A LIST OF RECORDS
function list_records() {
global $db;
global $viewdate;
//------>Change Viewdate to a timestamp
$timestamp1 = $viewdate;
list ($year1,$month1, $day1 ) = explode ("-", $timestamp1);
$timestamp1 = mktime (0, 0, 0, $month1, $day1, $year1 );
echo ("<p>The Timestamp for viewdate is: $timestamp1</p>");
//------>Add One year to the timestamp value.
$timestamp2 = ($timestamp1 + 31536000);
echo ("<p>The Timestamp for timestamp2 is: $timestamp2</p>");
//------>Change the timestamp back to viewdate2
list ($year2,$month2, $day2) = explode ("-", $timestamp2); <<---- BAD
$timestamp2 = mktime (0, 0, 0, $year2, $month2, $day2 );
echo ("<p>The viewdate for timestamp2 is: $timestamp2</p>");
Output =
The Timestamp for viewdate is: 957157200
The Timestamp for timestamp2 is: 988693200
The viewdate for timestamp2 is: -1
The viewdate for viewdate2 is: -1