Date manipulation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
squirto28
Forum Newbie
Posts: 11
Joined: Mon Mar 22, 2004 9:41 pm

Date manipulation

Post 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
Goowe
Forum Commoner
Posts: 94
Joined: Mon Mar 15, 2004 9:51 am
Location: Southeast Alaska

Post 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?
squirto28
Forum Newbie
Posts: 11
Joined: Mon Mar 22, 2004 9:41 pm

Post by squirto28 »

yes, that would be very helpful.

thanks

:wink:
Goowe
Forum Commoner
Posts: 94
Joined: Mon Mar 15, 2004 9:51 am
Location: Southeast Alaska

Post 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?
squirto28
Forum Newbie
Posts: 11
Joined: Mon Mar 22, 2004 9:41 pm

Post 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.
Chambrln
Forum Commoner
Posts: 43
Joined: Tue Dec 02, 2003 10:45 am
Location: Oregon

Post 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.
Post Reply