date calculation functions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vgshri
    New Member
    • Sep 2006
    • 2

    date calculation functions

    Hi all,

    Can anyone help me to calculate the date after months.

    Thanks in Advance
  • savanm
    New Member
    • Oct 2006
    • 85

    #2
    Hi

    try this

    $nextweek = time()+(7*24*60 *60);
    echo 'Next week'.date('d-m-Y',$nextweek)." \n";

    $nextmonth = time()+(30*24*6 0*60);
    echo 'Next month'.date('d-m-Y',$nextmonth). "\n";

    Regards

    savanm: enclose your code with code or php tags!! - moderator

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      Originally posted by savanm
      Hi

      try this

      $nextweek = time()+(7*24*60 *60);
      echo 'Next week'.date('d-m-Y',$nextweek)." \n";

      $nextmonth = time()+(30*24*6 0*60);
      echo 'Next month'.date('d-m-Y',$nextmonth). "\n";

      Regards

      savanm: enclose your code with code or php tags!! - moderator
      That is not going to work! Think about current date like 1 Jan, 31 Jan, etc.

      Instead use the standard PHP strtotime function and format the result. Like this:

      [php]<?php
      echo "1 week from now = " . date("Y-m-d", strtotime("+1 week"));
      echo '<br />';
      echo "1 month from now = " . date("Y-m-d", strtotime("+ 1 month"));
      ?>[/php]

      For more information on how to use the strtotime command, see strtorime function in the standard PHP manual.

      Ronald :cool:

      Comment

      Working...