In this tutorial learn how to select records/data from database between two dates.
MySQL-Easy to create a query for searching records/data between two dates, here multiple ways get the result of between two dates records like mysql function DATE_ADD() or function DATE() and many more .😆
Definition and Usage of DATE_ADD
The DATE_ADD() function adds a time/date interval to a date and then returns the date.
Syntax
MySQL Queries explain with Example
Table:
MySQL-Easy to create a query for searching records/data between two dates, here multiple ways get the result of between two dates records like mysql function DATE_ADD() or function DATE() and many more .😆
Definition and Usage of DATE_ADD
The DATE_ADD() function adds a time/date interval to a date and then returns the date.
Syntax
DATE_ADD(date, INTERVAL value)
MySQL Queries explain with Example
Table:
CREATE TABLE IF NOT EXISTS `users` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,`user_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,`pass_word` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,`u_type` enum('1','2','3','4') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '4',`created_at` date DEFAULT NULL,`updated_at` timestamp NULL DEFAULT NULL,`status` enum('0','1') COLLATE utf8mb4_unicode_ci NOT NULL,PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT=7 ;
1. Get the result between two dates using AND
2. Get the result using function DATE_ADD() also
SELECT * FROM users WHERE created_at >= '2019-01-01 00:00:00' AND created_at <= '2019-05-06 00:00:00'
2. Get the result using function DATE_ADD() also
SELECT users . * FROM users WHERE created_at >= '2011-01-01'AND created_at <= DATE_ADD( '2019-04-15', INTERVAL 1 DAY ) LIMIT 0 , 30
No comments:
Post a Comment