![]() | |
| |||||
| 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 :. Directory Submission Directory Submission :. News & Press Release Ireland GiveItSocks.com :. Used Cars Ireland, Car Parts & Car Audio Cars For Sale, Car Parts & Accessories :. I Have 2 Find It Directory SEF Directory |
| |||||
| Quote:
SELECT DATE_SUB('2008-08-01', INTERVAL 3 MONTH); I haven't used this function recently. It may also be dependent on the version of MySQL. Works in 4.n and 5.n. Regards...jmcc Last edited by jmcc; 24-07-2008 at 01:44 PM. Reason: sqlising |
| |||||
| 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.
__________________ :. Web Design & Development Web Design Ireland :. Search Engines Optimization Search Engines Optimization :. Directory Submission Directory Submission :. News & Press Release Ireland GiveItSocks.com :. Used Cars Ireland, Car Parts & Car Audio Cars For Sale, Car Parts & Accessories :. I Have 2 Find It Directory SEF Directory |
| |||||
| PHP Code:
__________________ my sites : irish poker / irish jobs / seo faq / advertise jobs free / green card / skiing |
| |||||
| Quote:
Regards...jmcc |
| |||||
| Quote:
I will let you know.
__________________ :. Web Design & Development Web Design Ireland :. Search Engines Optimization Search Engines Optimization :. Directory Submission Directory Submission :. News & Press Release Ireland GiveItSocks.com :. Used Cars Ireland, Car Parts & Car Audio Cars For Sale, Car Parts & Accessories :. I Have 2 Find It Directory SEF Directory |
| |||||
| 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.)
__________________ :. Web Design & Development Web Design Ireland :. Search Engines Optimization Search Engines Optimization :. Directory Submission Directory Submission :. News & Press Release Ireland GiveItSocks.com :. Used Cars Ireland, Car Parts & Car Audio Cars For Sale, Car Parts & Accessories :. I Have 2 Find It Directory SEF Directory |
| ||||
| 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.
__________________ :. Web Design & Development Web Design Ireland :. Search Engines Optimization Search Engines Optimization :. Directory Submission Directory Submission :. News & Press Release Ireland GiveItSocks.com :. Used Cars Ireland, Car Parts & Car Audio Cars For Sale, Car Parts & Accessories :. I Have 2 Find It Directory SEF Directory |
| Thread Tools | |
| Display Modes | |
|
|
| | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 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 |
| Successful Site in 12 Months with Google Alone | montyauto | Webmaster Articles | 11 | 18-02-2008 12:28 PM |
| 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 |