Advanced Search

Results 1 to 5 of 5

Thread: Get Year Duration

  1. #1
    Join Date
    Jan 2012
    Posts
    52
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default Get Year Duration

    Hello everybody,

    i have 2 dates in my database

    dateStart and dateEnd both stored as as type date: y-m-d (eg 2003-05-05)

    how can i get years.

    Thanking You
    Megha

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,156
    Thanks
    262
    Thanked 690 Times in 678 Posts

    Default

    One option:
    http://php.net/manual/en/function.mktime.php

    Another would be to use $date = explode('-',$date) on both (with different variable names of course) then just use $date[0] to get the year from each, then subtract. That assumes exactly equivalent formats all of the time.

    The first option will allow you a little more precision (even including months and days) and to know how much time or how many calendar years have passed; the second will only allow you to consider calendar years. (So Dec 31-Jan 1 = 1 year; Jan 1-Dec 31 = 0 years. Is that correct?)
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,627
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    check out the DateTime class as well.
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

  4. #4
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    243
    Thanks
    1
    Thanked 18 Times in 18 Posts

    Default

    Or
    PHP Code:
    echo date("Y"strtotime($row['dateStart'])); 

  5. #5
    Join Date
    Jan 2012
    Posts
    52
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default

    Resolved Get Year Duration .

    Thank you all for your quick feedback. I got a problem to get the total years. After that this is solved.

    At first the datediff() function gives the days. And then by dividing it by 365 it returns the years
    e.g.
    sum(datediff( `Date1` , `Date2` ) ) AS totalDays // this gives total days
    sum( datediff( `Date1` , `Date2` ) ) /365 AS totalYears // this gives total years

Similar Threads

  1. Determine the Video Duration
    By cancer10 in forum PHP
    Replies: 2
    Last Post: 04-13-2011, 02:41 AM
  2. Magnify duration not working
    By underbar in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 03-18-2010, 12:28 PM
  3. get day duration from pair dates
    By sabahan in forum PHP
    Replies: 4
    Last Post: 09-16-2009, 02:08 PM
  4. Fade Duration in Slideshow
    By xOli in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 03-30-2008, 10:03 AM
  5. Fade-in duration in fadeinslideshow
    By clair in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 01-17-2008, 10:07 AM

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
  •