This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function calculateDateDiff($strStart, $strEnd) { | |
$objStart = DateTime::createFromFormat("m/j/Y g:i:s A", $strStart); | |
$objEnd = DateTime::createFromFormat("m/j/Y g:i:s A", $strEnd); | |
// Return Total Seconds | |
return $objEnd->getTimestamp() - $objStart->getTimestamp(); | |
// Return formatted diference (7hrs 5mins and 43 seconds) | |
return $objStart->diff($objEnd)->format('%hhrs %imins and %sseconds '); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function calculateDateDiff($strStart, $strEnd) { | |
$parts = explode(' ', $strStart); | |
$dates = explode('/', $parts[0]); | |
$times = explode(':', $parts[1]); | |
$unix_start = mktime($times[0], $times[1], $times[2], $dates[0], $dates[1], $dates[2]); | |
$parts = explode(' ', $strEnd); | |
$dates = explode('/', $parts[0]); | |
$times = explode(':', $parts[1]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyDateTime extends DateTime | |
{ | |
protected $_daysOfTheWeek = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'); | |
public function lastDayOfTheMonth() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function format_datetime($examine_query) | |
{ | |
$split_query = explode("FROM", $examine_query); | |
$result = mysql_query($examine_query); | |
$numfields = mysql_num_fields($result); | |
for ($i = 0; $i < $numfields; $i++) | |
{ | |
$field_info = mysql_field_type($result, $i); | |
$field_name = mysql_field_name($result, $i); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$d = new DateTime(); | |
echo $d->format("r\n"); | |
//OUT: Wed, 06 Jul 2011 17:31:13 -0400 | |
$d->setTime(0, 0, 0); | |
$mt = clone $d; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// DATE/TIME Manipulation for dates from php to mysql and back again | |
// get time and date right now for inserting datetime into mysql | |
// the field in the db should be set as a mysql "datetime" field type | |
// First - set the local timezone | |
date_default_timezone_set('America/New_York') | |
// use this in a hidden form field to insert the time into db record | |
echo date('Y-m-d H:i:s',time()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// now | |
$date = date_create('2010-12-31 22:00:01', timezone_open('Europe/Amsterdam')); | |
// Buenos Aires | |
date_timezone_set($date, timezone_open('America/Argentina/Buenos_Aires')); | |
echo $date->format('Y-m-d H:i:s'); | |
// 2010-12-31 18:00:01 | |
// UTC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Comparison and Formatting | |
$start = new DateTime('now'); | |
$end = new DateTime('2014-02-01'); | |
echo 'Start: ' . $start->format('d M Y') . "\n"; | |
echo 'End: ' . $end->format('d M Y') . "\n"; | |
$diff = $end->diff($start); | |
echo 'Comparison: ' . ($start < $end ? 'Start is less than End' : 'End is less than Start') . "\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Validate a date. | |
* | |
* Source: http://www.phpro.org/examples/Validate-Date-Using-PHP.html | |
* | |
* @param string $date | |
* @param string $format | |
* @return bool | |
* | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Regex from http://www.pelagodesign.com/blog/2009/05/20/iso-8601-date-validation-that-doesnt-suck/ | |
function assertISO8601Date($dateStr) { | |
if (preg_match('/^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/', $dateStr) > 0) { | |
return TRUE; | |
} else { | |
return FALSE; | |
} | |
} |
NewerOlder