Skip to content

Instantly share code, notes, and snippets.

@fahdi
Created July 18, 2014 00:43
Show Gist options
  • Save fahdi/02d467be4f1327366dde to your computer and use it in GitHub Desktop.
Save fahdi/02d467be4f1327366dde to your computer and use it in GitHub Desktop.
Some date arithmetic code I wrote nearly a decade ago. Use at your own risk!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
echo date("M-d-Y", mktime(0, 0, 0, 12, 32, 1997))."<br/>";
echo date("M-d-Y", mktime(0, 0, 0, 13, 1, 1997))."<br/>";
echo date("M-d-Y", mktime(0, 0, 0, 1, 1, 1998))."<br/>";
echo date("M-d-Y", mktime(0, 0, 0, 1, 1, 98))."<br/>";
echo date("m",time());
echo date("m",time());
?>
<?php
// Adding 12 days to 12/32/1997 (mm/dd/yyyy)
echo date("M-d-Y", mktime(0, 0, 0, 12, 32+12, 1997))."<br/>";
//Jan-13-1998
echo "<br/>Month=".date('m',"12/32/1997");
echo "<br/>Date=".date('d',"12/32/1997");
echo "<br/>year=".date('Y',"12/32/1997");
$expire = '6-21-2007';
echo "Original date is ".date("M-d-Y",$expire);
$daystoincrement=32;
$yearstoincrement=1;
$monthstoincrement=2;
$expirenew=date("M-d-Y", mktime(0, 0, 0,date('m',$expire)+$monthstoincrement,date('d',$expire)+$daystoincrement,date('Y',$expire)+$yearstoincrement));
echo "<br/>Date after adding ".$daystoincrement." days, ".$yearstoincrement." years and ".$monthstoincrement." months equals " .$expirenew."<br/>";
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment