RE: [PHP] Date problem

From: Date: Mon, 02 Dec 2002 00:43:19 +0000
Subject: RE: [PHP] Date problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-126653@lists.php.net to get a copy of this message
> I want to get date from database, to increment ot decrement it with some > days, to show the date and after thath > if user confirm it to save it to database. There are a ton of ways you can do it. You can select the date and it's inc/dec value in the same statement: SELECT datecol, datecol + INTERVAL 1 DAY FROM yourtable WHERE ... Display whatever you need, if the user agrees to the new day, then issue an update query: UPDATE yourtable SET datecol = datecol + INTERVAL 1 DAY WHERE ... To make those queries dynamic, you can replace the '1' with a variable and assign it's value in PHP to either -1, 1, 2, 3, etc... $inc = -1; UPDATE yourtable SET datecol = datecol + INTERVAL $inc DAY WHERE ... Or... You can select out the date you have now, use strtotime() to make it into a unix timestamp (which PHP works with), and date() to format it however you want. If the user approves the new date, you can reformat the unix timestamp back to a YYYY-MM-DD format with date() or use FROM_UNIXTIME() in your query to insert/update the new date into the database... ---John Holmes...

« previous php.general (#126653) next »