Page 1 of 1

Date manipulation

Posted: Thu Mar 25, 2004 3:44 pm
by squirto28
I need extract the month and year of a date thats in the YYYY-mm-dd format. It's inputed by the user in a text box named mydate.

What I want is to use this date to search for all the records that correspond to the month and year they choose.

so if they pick 2004-03-07.
I want all the records of march 2004.

Any advice??????

Thanks

Posted: Thu Mar 25, 2004 3:56 pm
by Goowe

Code: Select all

<?php
$date = explode("-", $_POST['mydate']);

echo $date[0]."<br>\n"; // Echo's the year
echo $date[1]."<br>\n"; // Echo's the month
echo $date[2]."<br>\n"; // Echo's the day of the month
?>
http://us4.php.net/manual/en/function.explode.php

Did you also need help with selecting the information from the database (assuming it's a database) for records that came in the same year?

Posted: Thu Mar 25, 2004 9:16 pm
by squirto28
yes, that would be very helpful.

thanks

:wink:

Posted: Thu Mar 25, 2004 9:44 pm
by Goowe
I'm still assuming you're using a mysql database to store your information...

If so, how is your date stored in the database and what is the information for that column?

Posted: Fri Mar 26, 2004 10:44 am
by squirto28
It's in a sales table and it has the columns
store_no, date, netsales.

I want to pull store number xxxxx(which is from a cookie) I know how to do that. but I want to pull all of all the date and netsales for the month of lets say march 2004 for that store.

The month is from the user and they can pick any date from the java calander I have. date is in YYYY-mm-dd. And from that date the only thing that matters is the month and year.

Posted: Fri Mar 26, 2004 1:10 pm
by Chambrln
You could do something like

Code: Select all

<?php
$sql = "SELECT * FROM tablename WHERE store_no = '$_COOKIE[storeno]' AND date = '$date[0]'";

$query = mysql_query($sql);

?>
This is assuming your cookie variable is "storeno" and you use the code provided previously.