Python “time” Module
>>> import time >>> now = time.strftime("%Y-%m-%d %H:%M:%S") >>> now '2009-10-28 14:10:52' >>> tup = time.strptime(now, "%Y-%m-%d %H:%M:%S") >>> tup (2009, 10, 28, 14, 10, 52, 2, 301, -1) >>> unix = time.mktime(tup) >>> unix 1256710252.0 >>> tup2 = time.gmtime(unix) >>> tup2 == tup False >>> tup (2009, 10, 28, 14, 10, 52, 2, 301, -1) >>> tup2 (2009, 10, 28, 6, 10, 52, 2, 301, 0) >>> time.strftime("%Y-%m-%d %H:%M:%S", tup) '2009-10-28 06:10:52' >>> time.strftime("%Y-%m-%d %H:%M:%S", tup2) '2009-10-28 06:10:52'
Dates in PHP (Tomorrow, Yesterday, Today of a Given Date)
<?php
echo “<h4>Date Yesterday</h4>”;
$yesterday = date(“Y-m-d”, time()-86400);
echo $yesterday;
echo “<h4>Date Today</h4>”;
echo date(“Y-m-d”);
echo “<h4>Date Tomorrow</h4>”;
$tomorrow = date(“Y-m-d”, time()+86400);
echo $tomorrow;
echo “<hr>”;
echo “<h4>Previous Date from User-defined Date</h4>”;
$gdate = “2008-07-11”;
echo “(” . $gdate . ” supplied.) <br>”;
$dt = strtotime($gdate);
echo date(“Y-m-d”, $dt-86400);
echo “<h4>Next Date from User-defined Date</h4>”;
echo “(” . $gdate . ” supplied.) <br>”;
$dt = strtotime($gdate);
echo date(“Y-m-d”, $dt+86400);
// DAYS IN BETWEEN TWO DATES
function days_in_between($s, $e){
$d = array();
$s = strtotime($s);
$e = strtotime($e);
for($n=$s; $n<=$e; $n=$n+86400){
array_push($d, strftime(“%Y-%m-%d”, $n));
}
return $d;
}
?>