
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL DateTime Now()+5 days/hours/minutes/seconds?
To update the current date and time to 5 days, you need to use the Now() + 5. That would update the entire date-time i.e. days, hour, minutes and seconds. To understand this, let us create a table. The query to create a table is as follows −
mysql> create table UserInformationExpire -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserName varchar(10), -> UserInformationExpireDateTime datetime not null -> ); Query OK, 0 rows affected (0.83 sec)
Now you can insert some records in the table using insert command. The query is as follows −
mysql> insert into UserInformationExpire(UserName,UserInformationExpireDateTime) values('Maxwell','2019-02-09 23:56:27'); Query OK, 1 row affected (0.22 sec) mysql> insert into UserInformationExpire(UserName,UserInformationExpireDateTime) values('Carol','2018-11-21 15:45:21'); Query OK, 1 row affected (0.24 sec) mysql> insert into UserInformationExpire(UserName,UserInformationExpireDateTime) values('Bob','2019-01-22 16:30:35'); Query OK, 1 row affected (0.25 sec) mysql> insert into UserInformationExpire(UserName,UserInformationExpireDateTime) values('Larry','2017-12-25 17:20:33'); Query OK, 1 row affected (0.20 sec)
Display all records from the table using a select statement. The query is as follows −
mysql> select *from UserInformationExpire;
Output
+----+----------+-------------------------------+ | Id | UserName | UserInformationExpireDateTime | +----+----------+-------------------------------+ | 1 | Maxwell | 2019-02-09 23:56:27 | | 2 | Carol | 2018-11-21 15:45:21 | | 3 | Bob | 2019-01-22 16:30:35 | | 4 | Larry | 2017-12-25 17:20:33 | +----+----------+-------------------------------+ 4 rows in set (0.00 sec)
Here is your syntax to update the current datetime to 5 days/hours/minutes/seconds for id = 1 i.e. the current date is 2019-02-09 and it will be updated to 2019-02-14
mysql> update UserInformationExpire set UserInformationExpireDateTime = now()+interval 5 day where Id = 1; Query OK, 1 row affected (0.24 sec) Rows matched: 1 Changed: 1 Warnings: 0
Now check the table records once again to verify the date and time has been updated for only id 1 −
mysql> select *from UserInformationExpire where Id = 1;
Output
+----+----------+-------------------------------+ | Id | UserName | UserInformationExpireDateTime | +----+----------+-------------------------------+ | 1 | Maxwell | 2019-02-14 23:56:27 | +----+----------+-------------------------------+ 1 row in set (0.00 sec)
- Related Questions & Answers
- Converting seconds into days, hours, minutes and seconds in C++
- Converting seconds in years days hours and minutes in JavaScript
- Python program to convert seconds into hours, minutes and seconds
- C++ Program for converting hours into minutes and seconds
- Hours and minutes from number of seconds using JavaScript
- How can we create a MySQL function to find out the duration of years, months, days, hours, minutes and seconds?
- MySQL update datetime column values and add 10 years 3 months 22 days and 10 hours, 30 minutes to existing data?
- Remove seconds from MySQL Datetime?
- Add10 minutes to MySQL datetime format?
- MySQL Datetime to add days?
- Add 6 hours to now() function without using DATE_ADD() in MySQL?
- How to convert JavaScript seconds to minutes and seconds?
- How to add 30 minutes to datetime in MySQL?
- MySQL query to get only the minutes from datetime?
- How to add 5 hours to current time in MySQL?
Advertisements