Re: Date problem
| From: | Rosen | Date: | Mon, 02 Dec 2002 12:58:33 +0000 |
| Subject: | Re: Date problem | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-126709@lists.php.net to get a copy of this message | ||
Thanks for this,
I understand how to update in date in database, but I need when I get date
from database to increase or decrease before to save in database.
Can you help me for this ?
"John W. Holmes" <holmes072000@charter.net> wrote in message
news:001501c2999b$d24a71f0$7c02a8c0@coconut...
> > 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...
>
>