Forum Moderators: coopster

Message Too Old, No Replies

Finding future dates

         

artie2004

4:31 pm on Feb 19, 2005 (gmt 0)

10+ Year Member



Hi. I have a date formatted 02-19-2005. How do i write a script that will return 03-19-2006? Thanks.

ogletree

4:51 pm on Feb 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Need more detail. To answer your actual question:

echo "03-19-2006";

jatar_k

5:45 pm on Feb 19, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



do you mean add 1 month and add 1 year?

take a look at strtotime [php.net]

artie2004

5:50 pm on Feb 19, 2005 (gmt 0)

10+ Year Member



$date = mysql_query("select pharmacydate, DATE_FORMAT(pharmacydate,'%m-%e-%Y') AS date FROM orders, doctors, prescriptions, credit_order_status, physician_order_status, pharmacy_order_status, ship_order_status where orders.ordernum='$order_num' and orders.docid=doctors.userid and orders.ordernum=prescriptions.ordernum and orders.ordernum=credit_order_status.ordernum and orders.ordernum=physician_order_status.ordernum and orders.ordernum=pharmacy_order_status.ordernum and orders.ordernum=ship_order_status.ordernum and credit_order_status.creditstatus=1 and physician_order_status.physicianstatus=1 and pharmacy_order_status.pharmacystatus is NULL and ship_order_status.shipstatus is NULL");
$get_date = mysql_fetch_array($date);

//Outputs date (i.e. 02-19-2005)
echo $get_date['date'];

How do i convert this date to next year?

i.e. 02-19-2005 to 02-19-2006

Thanks.

jatar_k

6:00 pm on Feb 19, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



alright, maybe you dont want to look at strtotime ;)

$mydate = explode('-',$get_date['date']);
$future = strftime("%D",strtotime("+1 year",mktime(0,0,0,$mydate[0],$mydate[1],$mydate[2])));
echo $future;

artie2004

6:09 pm on Feb 19, 2005 (gmt 0)

10+ Year Member



Thanks everyone. I got it. Have a great day. :)