SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: date checking

  1. #1
    http://TheICE.co.uk/ The Eerie Network's Avatar
    Join Date
    Apr 2001
    Location
    London in the UK.
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    date checking

    Hi all, I want to write a function that will check a date given in yyyy-mm-dd format, and then see how many days have gone since that date, could someone help me with this please? I'm completly useless when it comes to adding up and subtracting dates, thank you
    Daniel Hollands
    New: My Webcam <-- Come and watch me doing what I do
    TheICE.co.uk <-- New sites for the best in UK lifestyle and Competitions.
    The ofDan.Network Forums <-- Come and join in the fun.

  2. #2
    SitePoint Wizard
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    2,617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What you need to do is make PHP display the date in it's numeric format, like 2001-09-25. Then you will be able to seperate those numbers and be able to subtract date you want.

    I will give it a swing for you when I get home. I don't have the means to try it out here on school .

  3. #3
    http://TheICE.co.uk/ The Eerie Network's Avatar
    Join Date
    Apr 2001
    Location
    London in the UK.
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, it's the whole 28,19,30,31 days in a month that screws me up

    just incase you re interested it's going to be used to check the status of links in a directory portal, and display a NEW image if they are new
    Daniel Hollands
    New: My Webcam <-- Come and watch me doing what I do
    TheICE.co.uk <-- New sites for the best in UK lifestyle and Competitions.
    The ofDan.Network Forums <-- Come and join in the fun.

  4. #4
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  5. #5
    SitePoint Wizard
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    2,617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    After seeing his code, I am certain mine will not work . I will still try to pull it off, we'll see. Mine looks much to simple compared to his.

    The Eerie Network, I would like to advice you to use freddy's solution .

    -Edit-

    Please go with freddy's solution, my attempt only produces a total gibberish of numbers.
    Last edited by Mark T.; Sep 25, 2001 at 09:12.

  6. #6
    http://TheICE.co.uk/ The Eerie Network's Avatar
    Join Date
    Apr 2001
    Location
    London in the UK.
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, I take it that you are talking about this:
    PHP Code:
    <?

        
    function date_compare($date1$date2$delim) {
            
    $t1 explode($delim$date1);
            
    $t2 explode($delim$date2);
            
    $tu1 mktime(0,0,0,$t1[0], $t1[1], $t1[2]);
            
    $tu2 mktime(0,0,0,$t2[0], $t2[1], $t2[2]);
            return 
    ceil(($tu1 $tu2) / 86400);
            }
        print 
    date_compare("07-10-01""06-10-00""-");

    ?>
    , the only problem with this is that I need 4 figure years, and from what I can see this uses 2 figure, do you know if this can be modified?

    Mark - Thank you for trying.
    Daniel Hollands
    New: My Webcam <-- Come and watch me doing what I do
    TheICE.co.uk <-- New sites for the best in UK lifestyle and Competitions.
    The ofDan.Network Forums <-- Come and join in the fun.

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't have to do anything withit except make the year 4 digits mktime() can use a two digit year or a 4 digit year.

    PHP Code:
        function date_compare($date1$date2$delim) {
            
    $t1 explode($delim$date1);
            
    $t2 explode($delim$date2);
            
    $tu1 mktime(0,0,0,$t1[0], $t1[1], $t1[2]);
            
    $tu2 mktime(0,0,0,$t2[0], $t2[1], $t2[2]);
            return 
    ceil(($tu1 $tu2) / 86400);
            }
        print 
    date_compare("07-10-01""06-10-00""-"); //prints 395
        
    print "<br>";
        print 
    date_compare("07-10-2001""06-10-2000""-"); //prints 395 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    http://TheICE.co.uk/ The Eerie Network's Avatar
    Join Date
    Apr 2001
    Location
    London in the UK.
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've said it before, and i'll say it again, you are a star, thank you
    Daniel Hollands
    New: My Webcam <-- Come and watch me doing what I do
    TheICE.co.uk <-- New sites for the best in UK lifestyle and Competitions.
    The ofDan.Network Forums <-- Come and join in the fun.


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
  •