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 12 of 12
  1. #1
    New Coder
    Join Date
    Jun 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question how to add two YYYY-MM-DD format dates properly????

    i m in a great trouble.............
    this has been a challenge for me..........
    i am not getting the idea for adding two dates YYYY-MM-DD format .....
    can anyone give the generalised formula for this i mean solve this....
    Ex Add 2005-4-14 and 2005-8-19..
    Plz help me

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i don't understand what you are trying to do. can you clarify some more?
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    PHP Code:
    $start '2005-04-14';
    $end '2005-08-19';

    $diff strtotime($end) -  strtotime($start);
    echo 
    'the difference between ' $start ' and ' .  $end ' is ' $diff ' seconds'

  • #4
    New Coder
    Join Date
    Jun 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Add 2005-4-14 and 2005-8-19 dates properly and display the results in the same format..........Actually i am making date converter.................Hope u eil help me

  • #5
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    What do you mean by add?

    devinemike has the right idea for comparing the 2 dates.

    Work out what you want manually and post the answer so we can see what you want...

  • #6
    New Coder
    Join Date
    Jun 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    not got my Prob???here it is more clear

    add
    2005-02-27 and
    11-10
    resulting ans is 2005-13-37
    but writing
    in proper format it becomes 2006-02-07
    That's the Result i want from aboove operation of date......i think u got my problem ..
    So..........

  • #7
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    PHP Code:
    <?php

    $date1 
    strtotime(2005-02-27); //convert date to proper format
    $date2 strtotime(2005-11-10); //convert date to proper format

    $year explode('-',$date2); //get the year
    $year strtotime($year[0]); //get number of seconds to that year

    $addon $date2 $year;
    $output $date1 $addon;

    echo 
    "New date: ".$output;

    ?>

  • #8
    New Coder
    Join Date
    Jun 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    still i didnt got????????

    but your result is New date: 2019890401
    the result i want is 2006-02-07
    can u modify it to above format.......again disturbing u........

  • #9
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #10
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Sorry, forgot to convert it back.
    PHP Code:
    <?php 

    $date1 
    strtotime(2005-02-27); //convert date to proper format 
    $date2 strtotime(2005-11-10); //convert date to proper format 

    $year explode('-',$date2); //get the year 
    $year strtotime($year[0]); //get number of seconds to that year 

    $addon $date2 $year
    $output $date1 $addon

    echo 
    "New date: ".date("Y-m-d",$output); 

    ?>

  • #11
    New Coder
    Join Date
    Jun 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    but the output is not the desired o/p???

    The date came in yyyy-mmm-dd format but its not the coorect format..
    Yours ans is:New date: 1904-11-06
    but mine desired ans is :2006-02-07
    Again mentioning my Problem:
    i want to add x months and y days to a yyyy-mmm-dd format..........
    for example :
    adding 11-10(mmm-dd) to
    2005-02-27 (yyyy-mmm-dd)
    should result
    2006-02-07 ....
    Plz again help me................

  • #12
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Nope, won't work.

    I give up.
    Last edited by SeeIT Solutions; 06-22-2005 at 09:57 AM.


  •  

    Posting Permissions

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