homepage Welcome to WebmasterWorld Guest from 23.22.179.210
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
manipulating with date type input
mysql php
ksugam




msg:3564439
 12:18 am on Feb 2, 2008 (gmt 0)

Hello,
I have a text field in which the users enter date in yyyy/mm/dd format. I get the value and put it in mysql query.
My concern is, i want to compare the data with previous month as well...

So if the user enters 2007/12/01, i will display data for dec 07. Now i want to compare dec 07 data with nov 07 data as well. So how can i calculate the previous month from the input?

Thanks!

 

yumigator




msg:3564561
 3:49 am on Feb 2, 2008 (gmt 0)

Try this, I didn't use comments because the variables seem pretty self-explanatory.

<?php
$date = "2007/12/01";
$datearray = explode("/", $date);
$month = $datearray[1];
echo("This month is ". $month . "<br>");
$lastmonth = $month - 1;
echo("Last month was " . $lastmonth);
?>

Just be careful that if the month is January, this will calculate last month as 0 (not 12). An if statement or two will take care of that.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved