This is a discussion on PHP Date Script - Substract 3 months within the Coding Help forums, part of the Webmaster Help category; Does any of you came across a PHP function to be able to remove 3 months from a specific date. ...
| |||||||
| Register | Forum Rules | FAQ | Donate | Calendar | Search | Today's Posts | Mark Forums Read |
| |||||
| Does any of you came across a PHP function to be able to remove 3 months from a specific date. I need to find records in the DB based on start date YEAR-MONTH-01 minus 3months and end date YEAR-MONTH-31, 30 or 28 minus 3 month depending on the dates given.
__________________ :. Web Design & Development Web Design Ireland :. Search Engines Optimization Search Engines Optimization :. Car Parts & Accessories Car Parts :. Cars Ireland Cars Ireland :. I Have 2 Find It Directory SEF Directory |
| |||||
| I am not sure if that will work with MySQL version but the problem I came across was with the date format I need which unfortunately has to be exact e.g. start date 2008-01-01 end date 2008-03-31 or 30 or 28/29 (February) I could manage the start date easily (already done) as all months starts with 01 but the end date seems to be a pain and I thought I might ask if there is a function already available as I might have to spend few hours to create one. |
| |||||
| PHP Code: |
| |||||
| Quote:
Regards...jmcc |
| |||||
| Quote:
I will let you know. |
| |||||
| As expected the mktime function gives the wrong date for February... ***k example: minus 1 month from march from (original 2008-01-01) 2007-10-01 to (original 2008-03-31) 2008-03-02 (wrong due to 28 or 29 days in Feb) example minus 3 months from given date from (original 2008-01-01) 2007-10-01 to (original 2008-03-31) 2007-12-31 (correct) example minus 4 months from given date from (original 2008-01-01) 2007-10-01 to (original 2008-03-31) 2007-12-01 (wrong due to 30 days only in Nov.) |
| ||||
| If you're just looking to return the month you could change the day value in mktime to 1 or anything <= 28. When doing stuff like this I'd normally give a time midway through the day to avoid day light savings problems as well. Code: =date("F",mktime(6, 0, 0, date("m")-3, 1, date("y")));
Edit: Just realised you need the end date of the month. You can use the t value in date to return the number of days in the given month, that should work. Last edited by Tom; 24-07-2008 at 03:11 PM.. |
| |||||
| I've been playing with dates recently. Such fun ! Louie you want to say remove 90 days or do you want to remove 3 months. Are you calculating the months as 30 days, 31 days or whatever number is in it ?
__________________ my sites : irish poker / irish jobs / seo faq / advertise jobs free / green card / skiing |
| |||||
| 90 days was the easy way out and is probably what I am going to do at the end then compare the days in a month with the day the function gives and replace it if needed to do so. I need exact dates - last day of the month is compared correctly. |
| Tags |
| date, months, php, script, substract |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Successful Site in 12 Months with Google Alone | montyauto | Webmaster Articles | 12 | 20-04-2009 10:56 AM |
| Quarterly Irish Webmaster Meetup - Proposal for date in March / April? | gav240z | General Chat | 48 | 21-07-2008 07:07 PM |
| Fix this lightbox script | wheres me jumpa | Coding Help | 3 | 05-06-2008 11:20 AM |
| php compare date | louie | Coding Help | 4 | 08-12-2006 09:50 AM |
| What's this script? | blacknight | Webmaster Discussion | 0 | 23-08-2006 10:49 PM |
| ||||
| | ![]() | |||
| | ||||