
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Get last second of a date in MySQL?
To get the last second of a date in MySQL, use the INTERVAL command. Let us first create a table −
mysql> create table DemoTable -> ( -> JoiningDatetime datetime, -> DueDatetime datetime -> ); Query OK, 0 rows affected (0.55 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(JoiningDatetime) values('2019-11-03 12:34:54'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(JoiningDatetime) values('2019-10-04 12:34:54'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+---------------------+-------------+ | JoiningDatetime | DueDatetime | +---------------------+-------------+ | 2019-11-03 12:34:54 | NULL | | 2019-10-04 12:34:54 | NULL | +---------------------+-------------+ 2 rows in set (0.00 sec)
Here is the query to get the last second of a date in MySQL −
mysql> update DemoTable -> set DueDatetime=DATE(JoiningDatetime) + INTERVAL 1 DAY - INTERVAL 1 SECOND; Query OK, 2 rows affected (0.19 sec) Rows matched: 2 Changed: 2 Warnings: 0
Let us check the table records once again −
mysql> select *from DemoTable;
This will produce the following output −
+---------------------+---------------------+ | JoiningDatetime | DueDatetime | +---------------------+---------------------+ | 2019-11-03 12:34:54 | 2019-11-03 23:59:59 | | 2019-10-04 12:34:54 | 2019-10-04 23:59:59 | +---------------------+---------------------+ 2 rows in set (0.00 sec)
- Related Articles
- Get the second last row of a table in MySQL?
- How to get the second last record from a table in MySQL?
- Get the first and last date of next month in MySQL?
- Get the date/time of the last change to a MySQL database?
- How to get the second-to-last element of a list in Python?
- Get Last Entry in a MySQL table?
- How to get the records of the last two days from the current date in MySQL?
- How to find last date from records with date values in MySQL?
- Get total in the last row of MySQL result?
- Get the index of last substring in a given string in MySQL?
- Increment date/time value by second with MySQL query?
- Get maximum date from a list of varchar dates in MySQL
- How to compare the first date and the last date from a MySQL column with date records?
- Get the last days of all the months in MySQL?
- How to get the creation date of a MySQL table?

Advertisements