SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Urgent! PHP Date Question

    Hai folks,

    assume 18-2-2012 is an employee id expiry date.
    i want to alert the management prior to 30 days of expiry of this id.
    but below code does not work. pls help me?


    $exp_dt=strtotime("18-2-2012");
    if ($exp_dt == strtotime("+30 days")){
    echo "This id will going to expire in 30 days";
    }

  2. #2
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    hai folks,

    i think i found the solution. feel free to comment on this.

    PHP Code:
    $exp_dt="18-2-2012";

    $alert_dt=getdate(strtotime("+31 days")); 
    $dd=$alert_dt['mday'];
    $mm=$alert_dt['mon'];
    $yy=$alert_dt['year'];
    $alert_dt=$dd "-" $mm "-" $yy;
    if (
    $exp_dt == $alert_dt){
       echo 
    "This id will going to expire in 30 days";


  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    PHP Code:
    if(strtotime($exp_date) < strtotime('+ 31 days')){
    echo 
    "This id will going to expire in 30 days"

    Untested, but something like that should work.

    I'd personally test that with dates like 6th May vs 5th June to be sure though

  4. #4
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    PHP Code:
    if(strtotime($exp_date) < strtotime('+ 31 days')){
    echo 
    "This id will going to expire in 30 days"

    Untested, but something like that should work.

    I'd personally test that with dates like 6th May vs 5th June to be sure though
    Thanks for the reply buddy, i got it...


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
  •