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
Date manipulation
Moderator: General Moderators
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
?>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?
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.
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.
You could do something like
This is assuming your cookie variable is "storeno" and you use the code provided previously.
Code: Select all
<?php
$sql = "SELECT * FROM tablename WHERE store_no = '$_COOKIE[storeno]' AND date = '$date[0]'";
$query = mysql_query($sql);
?>