SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: php date field

  1. #1
    ********* Addict DLG_1's Avatar
    Join Date
    Jun 2000
    Location
    Texas, USA
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php date field

    I need to add 15 days to a returned date in php, how do i do this?

    so far i've done this:
    $dueDate is a passed variable.
    Code:
    $dateToday	= gmdate("M d y");
    $targetDate	= $dueDate + 15;
    but this seems to add 11 + 15...but that's not what I want.

    I then compare $dateToday and $targetDate to each other.
    thanks,
    dlg_1
    Last edited by DLG_1; Nov 1, 2001 at 12:11.

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2001
    Location
    London
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use mktime();

    Example:

    PHP Code:
    Use mktime(); 

                           
    Example

                               
    PHP:



                               
    $tomorrow  mktime (0,0,0,date("m")  ,date("d")+1,date("Y")); 

    -- | StEaLThEn |--

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2001
    Location
    London
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ups!!! I mean:
    Use mktime();




    PHP Code:
     $tomorrow  mktime (0,0,0,date("m")  ,date("d")+1,date("Y")); 

    -- | StEaLThEn |--

  4. #4
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should use unix dates for this, it will be easy.

    Use mktime() on the passed variable $dueDate, to make it a unix date in seconds, then add 86400*15 to it. (86400 seconds is a 24h day)
    Then use date() on the resulting unix date to format it back to $dueDate 's original format.

    Edit: ah, beat me to it
    Last edited by Michel V; Nov 1, 2001 at 13:33.

  5. #5
    ********* Addict DLG_1's Avatar
    Join Date
    Jun 2000
    Location
    Texas, USA
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    hmm...

    $tomorrow = mktime (0,0,0,date("m") ,date("d")+1,date("Y"));
    $tomorrow = date($tomorrow);
    echo"tomorrow's date: $tomorrow";







    what am i doing wrong?

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2001
    Location
    London
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't need to call date() after mktime()

    so, just use:
    PHP Code:
    $tomorrow mktime (0,0,0,date("m") ,date("d")+1,date("Y")); 
                              
    $tomorrow date($tomorrow); 
                              echo
    "tomorrow's date: $tomorrow"
    hope it works
    -- | StEaLThEn |--

  7. #7
    SitePoint Enthusiast
    Join Date
    Oct 2001
    Location
    London
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh god It should have slept a little bit more last night, what I mean is:

    PHP Code:
    $tomorrow mktime (0,0,0,date("m"); 
                            
                              echo
    "tomorrow's date: $tomorrow"
    -- | StEaLThEn |--

  8. #8
    ********* Addict DLG_1's Avatar
    Join Date
    Jun 2000
    Location
    Texas, USA
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nope!

  9. #9
    ********* Addict DLG_1's Avatar
    Join Date
    Jun 2000
    Location
    Texas, USA
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    with a little help from phpbuilder.com and a wrox book that I have...the answer is this:

    Code:
    $dateToday	= time();
    				$dueDate	= mktime($dueDate);
    				echo"this is the duedate in unix timestamp format: $dueDate<br>";
    				$targetDate	= $dueDate + 1296000;
    				$targetDate	= date("M j Y", $targetDate);
    				echo"the absolute latest is: $targetDate<p>";

  10. #10
    ********* Addict DLG_1's Avatar
    Join Date
    Jun 2000
    Location
    Texas, USA
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay, that really didn't work. i need help badly.
    i'm so wound up about this that there's no way that i'll find the solution unless I take time away from problem. but I'd rather someone help me with this.

    okay here goes again.

    i have a database that holds a date as a DATE datatype:

    2001-12-01

    I want to compare that with the Unix Timestamp for Today (or Mktime() with no params so will default to now).

    however, I need to make a comparison between both dates and even add 15 days to the DAY FIELD. (01 in the example above).

    someone please help.

    DLG_1


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
  •