PEAR Date library - creating a new Date
Posted: Wed Mar 04, 2009 3:10 pm
I've run into an issue with the PEAR Date library that is mystifying me. I've used Date for a while now, and it can get a little tricky, but this is beyond me.
I'm using PHP v4.3.9
Using the PEAR Date library
$_REQUEST holds three variables (comes from a Javascript calendar) that define the date. I turn them into one string via sprintf, then get a new Date object.
However, the newly created Date object is blank, even though $x is a String type and does print out properly, like "2007-01-01".
What is baffling me is that if I simply say...
... in this case the $targetDate object is created properly. I just can't seem to find a way that $x in the first example is different from $x in the second. I've looked at whether $x is being typed correctly and it is.
Thank you for any assistance. I've looked around for information that would help me but I find I'm just beating my head against the wall.
I'm using PHP v4.3.9
Using the PEAR Date library
$_REQUEST holds three variables (comes from a Javascript calendar) that define the date. I turn them into one string via sprintf, then get a new Date object.
Code: Select all
$x = sprintf("%s-%s-%s", $_REQUEST['y'], $_REQUEST['m'], $_REQUEST['d'] ) ;
$targetDate = new Date( $x ) ; What is baffling me is that if I simply say...
Code: Select all
$x = "2007-01-01";
$targetDate = new Date( $x ) ;Thank you for any assistance. I've looked around for information that would help me but I find I'm just beating my head against the wall.