Irish SEO,  Marketing & Webmaster Discussion
 

 

Go Back   Irish SEO, Marketing & Webmaster Discussion > Webmaster Help > Coding Help


Notices

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 24-07-2008, 01:30 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 1,934
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
louie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud of
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default PHP Date Script - Substract 3 months

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
Reply With Quote
  #2 (permalink)  
Old 24-07-2008, 01:40 PM
jmcc's Avatar
Wannabe Geek
 
Join Date: Feb 2006
Posts: 285
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
jmcc has a spectacular aura about
Default

Quote:
Originally Posted by louie View Post
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.
Not sure about PHP but I think that the DATE_SUB() function in MySQL will allow you to subtract months. Something like this:
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
Reply With Quote
  #3 (permalink)  
Old 24-07-2008, 01:47 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 1,934
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
louie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud of
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

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
Reply With Quote
  #4 (permalink)  
Old 24-07-2008, 01:51 PM
paul's Avatar
Web Whore
 
Join Date: Dec 2006
Location: .de
Posts: 981
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
paul has much to be proud ofpaul has much to be proud ofpaul has much to be proud ofpaul has much to be proud ofpaul has much to be proud ofpaul has much to be proud ofpaul has much to be proud ofpaul has much to be proud ofpaul has much to be proud ofpaul has much to be proud of
Default

PHP Code:
<?php
$3monthsago mktime(000date("m")-3date("d"), date("y"));
echo 
"3 months ago was ".date("m/d/y", $3monthsago ); 
?>
__________________
my sites :
irish poker / irish jobs / seo faq / advertise jobs free / green card / skiing
Reply With Quote
  #5 (permalink)  
Old 24-07-2008, 01:58 PM
jmcc's Avatar
Wannabe Geek
 
Join Date: Feb 2006
Posts: 285
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
jmcc has a spectacular aura about
Default

Quote:
Originally Posted by louie View Post
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.
Perhaps using the DATE_SUB to generate the month and then using a limiter on the DATE function might work or alternatively (in a major kludge) use a number of DATE_SUB queries to generate the limits. Subtracting 3 months gives the lower limit, subtracting two months and then a day gives the upper limit. Very inelegant but it may work.

Regards...jmcc
Reply With Quote
  #6 (permalink)  
Old 24-07-2008, 02:08 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 1,934
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
louie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud of
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

Quote:
Originally Posted by paul View Post
PHP Code:
<?php
$3monthsago mktime(000date("m")-3date("d"), date("y"));
echo 
"3 months ago was ".date("m/d/y", $3monthsago ); 
?>
I was just looking at mktime - just need to run few tests.

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
Reply With Quote
  #7 (permalink)  
Old 24-07-2008, 02:45 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 1,934
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
louie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud of
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

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
Reply With Quote
  #8 (permalink)  
Old 24-07-2008, 03:02 PM
Tom Tom is offline
Wannabe Geek
 
Join Date: Jan 2007
Location: Kildare, Ireland
Posts: 172
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Tom is a splendid one to beholdTom is a splendid one to beholdTom is a splendid one to beholdTom is a splendid one to beholdTom is a splendid one to beholdTom is a splendid one to beholdTom is a splendid one to behold
Default

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.
__________________
MGS Web Design - Web Design Kildare, Web Design Ireland

Last edited by Tom; 24-07-2008 at 03:11 PM.
Reply With Quote
  #9 (permalink)  
Old 24-07-2008, 03:47 PM
paul's Avatar
Web Whore
 
Join Date: Dec 2006
Location: .de
Posts: 981
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
paul has much to be proud ofpaul has much to be proud ofpaul has much to be proud ofpaul has much to be proud ofpaul has much to be proud ofpaul has much to be proud ofpaul has much to be proud ofpaul has much to be proud ofpaul has much to be proud ofpaul has much to be proud of
Default

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
Reply With Quote
  #10 (permalink)  
Old 24-07-2008, 04:29 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 1,934
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
louie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud of
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
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


All times are GMT +1. The time now is 07:30 AM.


Powered by: vBulletin Version 3.7.2, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.

Search Engine Friendly URLs by vBSEO 3.2.0