SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    belfast
    Posts
    386
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Customisation of date upload display ...

    Hey guys,

    Completely stumped ... heres what I'm trying to do. When I upload a page I want it to say that one of 3 things depending on the upload time:

    Upload = current day then
    1. i.e uploaded today - it says Uploaded: Today 9.15am

    OR Upload = current_date -1 then
    2. i.e. uploaded yesterday - it says Uploaded: Yesterday 9.15am

    OR upload = any other time
    3. i.e. uploaded more than 1 day ago - it says Upload Nove 23, 2004

    These customised displays are dependent on the time stamp of the file that is being accessed ... and the server is in the states so all when I update a file here in ireland and upload it to my host who is in the states it appears with an upload time 5hrs behind me, as is expected.

    Now my problem is that I convert all the data into GMT (as I'm in Ireland) and then calculate the times from this. Now this scripts works throughout the day ... but at 12am GMT or 7pm EST the wrong data is returned.

    PHP Code:
    <?php
    function last_updated($filename)
    {

    // Display the date
    // eg. Jan 25 2004

    $last_modified filemtime($filename);
    $last_modified_day gmdate("M d Y"$last_modified);
    $last_modified_time gmdate("g:ia"$last_modified);

    $today gmmktime(0,0,0,date("m") ,date("d"),date("Y"));
    $today_day gmdate("M d Y"$today);

    $yesterdaygmmktime(0,0,0,date("m"),date("d")-1,date("Y"));
    $yesterday_day gmdate("M d Y"$yesterday);

    if (
    $last_modified_day == $today_day){
        
    $last_modified 'Today ' $last_modified_time;
    }
    elseif (
    $last_modified_day == $yesterday_day){
        
    $last_modified 'Yesterday ' $last_modified_time;
    }
    else{
        
    $last_modified $last_modified_day;
    }
    echo 
    "<b>Last Updated: </b>" $last_modified;
    }
    ?>
    At 12am GMT for the 23rd Nov it returns today_day as being the 22nd - and I dont have a clue why since I changed the times/dates into GMT with the function gmmktime() and gmdate()

    You can see the use of the code here

    Any Ideas?

    Cheers,

    Ronan

  2. #2
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    belfast
    Posts
    386
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its ok guys ... think I got it ... still a bit of tidying up to do but it seems to work a ok :-)

    PHP Code:
    <?php
    function last_updated($filename)
    {

    // Display the date
    // eg. Jan 25 2004

    $todaydiff "5";//server-to-GMT time
    $timeadjust = ($todaydiff 60 60);
    $gmt_today_date date("M d Y",time() + $timeadjust);

    $yestdiff "19"//24hrs - server-to-GMT time = 19hrs
    $timeadjust = ($yestdiff 60 60);
    $gmt_yest_date date("M d Y",time() - $timeadjust);

    $last_modified_file filemtime($filename);
    $last_modified_file_day gmdate("M d Y"$last_modified_file);
    $last_modified_file_time gmdate("g:ia"$last_modified_file);

    if (
    $last_modified_file_day == $gmt_today_date){
        
    $last_modified 'Today ' $last_modified_file_time;
    }
    elseif (
    $last_modified_file_day == $gmt_yest_date){
        
    $last_modified 'Yesterday ' $last_modified_file_time;
    }
    else{
        
    $last_modified $last_modified_file_day;
    }
    echo 
    "<b>Last Updated: </b>" $last_modified;
    }
    ?>


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
  •