网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 服务器与数据库 > MySQL
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

Reply
 
Thread Tools Display Modes
  #1   IP: 112.87.30.158
Old 2015-04-19, 08:56 AM
Garwin Garwin is offline
初级会员
 
Join Date: 2008-04-24
Posts: 1
Garwin 现在声名狼藉
Default Update a date value?

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?
Reply With Quote
  #2   IP: 112.87.30.158
Old 2015-04-19, 08:58 AM
Gasconade Gasconade is offline
初级会员
 
Join Date: 2005-11-10
Posts: 1
Gasconade 现在声名狼藉
Default

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');
}
Or you can do it with mysql like:
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));
Reply With Quote
  #3   IP: 112.87.30.158
Old 2015-04-19, 08:58 AM
Gastonville Gastonville is offline
初级会员
 
Join Date: 2008-06-06
Posts: 1
Gastonville 现在声名狼藉
Default

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'
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 03:22 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.