Return to Snippet

Revision: 33383
at October 8, 2010 07:50 by vagrantradio


Initial Code
function strip_zeros_from_date( $marked_string = "" ){
		//Remove any Zeros in the date
		$no_zeros = str_replace('*0', '', $marked_string );
		//Remove the Asterik regardless of no Zeros
		$cleaned_string = str_replace('*', '', $no_zeros );
		
		return $cleaned_string;
	}

	//Number of seconds since January 1, 1970
	echo $time = time();
	echo "<br /><br />";

	//Make a timestamp using mktime( $hr, $min, $sec, $mo, $day, $yr )
	echo $mktime =  mktime( 2, 30, 45, 10, 1, 2009 );
	echo "<br /><br />";

	//Convert this date to a string
	echo $date = strtotime("September 15, 2000");
	echo "<br /><br />";			

	//Convert Last Monday to a String
	echo $last_monday = strtotime("last Monday");
	echo "<br /><br />";			

	//Convert 1 day from today to a String
	echo $tomorrow = strtotime("+1 day");
	echo "<br /><br />";			

	//Check if this date is valid (February 31st)
	echo $valid_date = checkdate( 2, 31, 2000 ) ? "true" : "false";
	echo "<br /><br />";			
	
	//Format a Unix Timestamp into something human readable (http://php.net/manual/en/function.strftime.php)
	//The asterik is neat little hack that will help us build a helper function
	echo strip_zeros_from_date( strftime( "*%m/*%d/%y", $last_monday ) );

	echo "<br /><br />";
	
	//Format your date in PHP for MySQL
	$dt = time();
	$mysql_datetime = strftime("%Y-%m-%d %H:%M:%S", $dt);
	echo $mysql_datetime;

Initial URL

                                

Initial Description
Self Explanatory

Initial Title
Basic PHP Date and Time Functions

Initial Tags
php

Initial Language
PHP