...

View Full Version : how to add two YYYY-MM-DD format dates properly????



DineSh
06-19-2005, 08:09 PM
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

raf
06-19-2005, 10:23 PM
i don't understand what you are trying to do. can you clarify some more?

devinemke
06-20-2005, 12:17 AM
$start = '2005-04-14';
$end = '2005-08-19';

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

DineSh
06-20-2005, 05:29 AM
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

SeeIT Solutions
06-20-2005, 06:31 AM
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...

DineSh
06-20-2005, 08:43 AM
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..........

SeeIT Solutions
06-20-2005, 09:16 AM
<?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;

?>

DineSh
06-20-2005, 04:44 PM
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........

marek_mar
06-20-2005, 10:08 PM
date() (http://www.php.net/date)

SeeIT Solutions
06-20-2005, 11:30 PM
Sorry, forgot to convert it back.

<?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);

?>

DineSh
06-22-2005, 08:22 AM
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................

SeeIT Solutions
06-22-2005, 08:51 AM
Nope, won't work.

I give up.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum