![]() |
|
|||||||
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
#1
IP: 112.87.30.158
|
|||
|
|||
|
What is the easiest way to update a date?
In my database I have a field called mydate that is setup as a timestamp datatype. (It as to be this datatype). My dates are listed as either: 2013-07-25 00:00:00 or 0000-00-00 00:00:00 Meaning they either have a data or just zeroes, but never empty. Edit: Thank you all! I sort of combined all that you said and made it work. Now lets say I wanted to increase any give date with 10 days how would I accomplish that? The first one, July 25th 2013 would become 2013-08-04 00:00:00 and the other would become 2013-06-18 00:00:00 (at the time of posting it's June the 8th). How to? |
|
#2
IP: 112.87.30.158
|
|||
|
|||
|
With PHP you can do something like:
Code:
if($mydate_from_db > $present_date){
$mydate_from_db = strtotime($mydate_from_db, '+ 10 days');
} else {
$mydate_from_db = strtotime($present_date, '+ 10 days');
}
Code:
UPDATE yourtable SET mydate = IF(mydate = '0000-00-00 00:00:00', '2013-06-18 00:00:00', DATE_ADD(mydate, INTERVAL 10 DAY)); |
|
#3
IP: 112.87.30.158
|
|||
|
|||
|
You can do it in MySql directly:
Code:
UPDATE
my_table
SET
my_date = my_date + INTERVAL 10 DAY
WHERE
DATE(my_date) >= '2013-06-01'
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Insert/ Update random date in MySQL | Illiopolis | MySQL | 1 | 2015-04-19 06:18 AM |
| Random MySQL date | Kimberling City | MySQL | 1 | 2015-04-18 11:09 PM |
| MySQL Generate Random Date | Kensington | MySQL | 0 | 2015-04-18 11:02 PM |
| MySql避免重复插入记录方法(ignore,Replace,ON DUPLICATE KEY UPDATE) | Langdon | MySQL | 0 | 2015-01-14 03:34 PM |
| Update to vbulletin v4.2.2 | topvip | vBulletin技术交流 | 0 | 2014-03-21 04:45 PM |