PDA

View Full Version : date format problem


seetz10
03-05-2004, 05:34 PM
hi,

I want to use a date that is selected in a drop down by the user from
a previous page in a sql query.
The date is $thedate and in the format eg 12/04/2004 when i post the
value.



$thedate = $_POST[sel_date];



but because the format is in a string i cannot compare it to a value in my
table in the database because the value in the databse is in the format 2004-04-12.


I have tried to use this ....




$datearray = getdate($thedate);

foreach ($datearray as $key => $val)
{
print "$key= $val<br>";
}




But i just get the unix epoch value. I guess this is because the arguement
for getdate() is not a not a timestamp but a string.


Can anyone help me figure what i can do to solve this problem.


Thanks

bcarl314
03-05-2004, 06:05 PM
Check out the mktime() function on the php.net site. It may help.

piz
03-05-2004, 11:04 PM
I want to use a date that is selected in a drop down by the user from
a previous page in a sql query.
The date is $thedate and in the format eg 12/04/2004 when i post the
value.I wouldn't do that...
Have a look at the W3C guidelines.
--> http://www.w3.org/QA/Tips/iso-date
$thedate = $_POST[sel_date];This is bad php syntax, use quotes for array keys.
$_POST["sel_date"]; or $_POST['sel_date'];
but because the format is in a string i cannot compare it to a value in my
table in the database because the value in the databse is in the format 2004-04-12.--> http://php.net/strtotime
--> http://www.gnu.org/software/tar/manual/html_chapter/tar_7.html (for the input formats of strtotime)$datearray = getdate($thedate);
foreach ($datearray as $key => $val)
{
print "$key= $val<br>";
}The function getdate requires a timestamp as argument.
--> http://php.net/getdateBut i just get the unix epoch value. I guess this is because the arguement
for getdate() is not a not a timestamp but a string.Exactly.Can anyone help me figure what i can do to solve this problem.hope I helped.

saludo
piz