Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    262
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Difference between 2 dates

    You know in ASP you can use the DateDiff function to determine difference in days between 2 given dates.... how can this be done in PHP with the date format as: dd mmm yyyy? any examples?

    Cheers

  • #2
    New Coder
    Join Date
    Sep 2003
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Unsure, but using a timestamp, for each xxxxxx seconds = 1 day..

    Duration of time Time in Seconds
    One Second 1
    One Minute 60
    One Hour 3600
    One Day 86400
    One Week 604800
    One Year 31449600
    One Leap Year 31536000
    One Decade 314496000
    One Average Life-Time 2515968000
    One Century 3144960000
    One Millennium 31449600000

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    262
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Converting Date fromat from Oracle

    Hi,

    I'm pulling dates from an oracle database in the format DD/MM/YYYY - e.g. - 21/07/2003

    I would like to convert it to - DD MMM YYYY - e.g. 21 Jul 2003

    When I try:-

    PHP Code:
    print date("d M Y"strtotime("$due_date")); 
    it returns:

    07 Sep 2004

    So I guess its thinking my month is the day and the day is the month and therefore changing the year....

    Any ideas to correct this?

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    262
    Thanks
    0
    Thanked 0 Times in 0 Posts
    any ideas on this?

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    262
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've been also trying to change its format in the PL/SQL code in my stored procedure using TO_CHAR (trying a different angle)

    but I can't seem to do that either...

    I'm stuck in a rut!!

    any one else had this prob with oracle date formats?

  • #6
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    messy but works ..

    PHP Code:
    <?php
    function date_diff$d1 $d2 ){
        
    $bits explode' ' $d1 ) ;$d1=mktime (0,0,0,$bits[1],$bits[0],$bits[2]); 
        
    $bits explode' ' $d2 ) ;$d2=mktime (0,0,0,$bits[1],$bits[0],$bits[2]); 
        
    $diff = ($d1>$d2) ? $d1-$d2 $d2-$d1;
        return (
    $diff 24 ) / 3600;
    }
    echo 
    date_diff'10 02 2000','10 03 2000' ) ;
    ?>
    your DB should be able to return a timestamp , mysql can calculate the difference between dates , I am sure Oracle can of course but I would not know how, these things are best done via the DB
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #7
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    , strtotime() requires some textual content ... eg it can work out what 'next thursday' means as well as '10 June 2003' , but just given numbers it has no way of telling which is the month & which is the day etc .. see my post in your other thread .. am merging the 2 threads BTW as its basically the same subject.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •