SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2006
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Date question - head spin!

    Hello all,

    I need some PHP code to execute on the start of the 3rd week of the current month!

    The code needs to send an email to people 1 week (7 days) before the end of the current month. I am getting headaches trying to work it out!

    The code will be called daily by a cron and the code will first check to see if today is 7 days before the end of the current month - if true then email.

    Cheers

    marc

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    http://us.php.net/manual/en/function.date.php

    date('t') gives the number of days in the month, so subtract 7 and you have the target date

    PHP Code:
    if (date('j') == (date('t') - 7)) {
      echo 
    "Today is 7 days before the end of the month";

    Last edited by Dan Grossman; May 2, 2009 at 20:17. Reason: Removed extra $

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2006
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect Dan!!

    Thank you for this!

    Cheers

    Marc

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2006
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I also removed the "$" from the first date function call in your example above - I assumed its a typo

    Cheers

    Marc


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •