Jump to content

[SOLVED] strtotime Question?


cooldude832

Recommended Posts

try this if this would help.

 

<?php
$str = 'Not Good';

// previous to PHP 5.1.0 you would compare with -1, instead of false
if (($timestamp = strtotime($str)) === false) {
    echo "The string ($str) is bogus";
} else {
    echo "$str == " . date('l dS \o\f F Y h:i:s A', $timestamp);
}
?> 

 

http://php.net/strtotime

this made it happy finally

<?php
$time2 = explode(" ",$time[0]);
	switch($time2[2]){
		case Jan:
			$month = 1;
		break;
		case Feb:
			$month = 2;
		break;
		case Mar:
			$month = 3;
		break;
		case Apr:
			$month = 4;
		break;
		case May:
			$month = 5;
		break;
		case Jun:
			$month = 6;
		break;
		case Jul:
			$month = 7;
		break;
		case Aug:
			$month = 8;
		break;
		case Sep:
			$month = 9;
		break;
		case Oct:
			$month = 10;
		break;
		case Nov:
			$month = 11;
		break;
		case Dec:
			$month = 12;
		break;
		default:
			$month = 1;
	}
	$time3 = $time2[3]."/".$month."/".$time2[1]." ".$time2[4];
	$time4 = strtotime($time3);
?>

I did a quick test using:

<?php
$strs = array('1 Sep 2007 21:06:11','2 Sep 2007 13:45:31','2 Sep 2007 13:45:31','3 Sep 2007 01:40:42');
foreach($strs as $dte)
echo date('F j, Y  g:i A',strtotime($dte)).'<br>';
?>

 

And got the following printed:

September 1, 2007 9:06 PM
September 2, 2007 1:45 PM
September 2, 2007 1:45 PM
September 3, 2007 1:40 AM

 

which is correct.

 

Please post the code that gave you the incorrect results.

 

Ken

starting with

 

Received: (qmail 6265 invoked by uid 399); 29 Nov 2007 02:55:45 -0000 Received: from rv-out-0910.google.com (209.85.198.185) by manhattan.worldispnetwork.com with SMTP; 29 Nov 2007 02:55:45 -0000 Received: by rv-out-0910.google.com with SMTP id k15so1441365rvb for <[email protected]>; Wed, 28 Nov 2007 18:55:44 -0800 (PST) Received: by 10.140.135.20 with SMTP id i20mr3017628rvd.1196304944936; Wed, 28 Nov 2007 18:55:44 -0800 (PST) Received: by 10.140.202.18 with HTTP; Wed, 28 Nov 2007 18:55:44 -0800 (PST)

 

<?php

	$time = explode(";",$value['Header']['Received']);
	$time = explode(" -",$time[1]);
	$time_a = trim($time[0]);
	$time_a = strtotime($time_a); 
	echo "Date: ".date("Y/m/d",$time_a)."<br />";

}
?>

outputs: Date: 2007/09/01

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.