Linux, FreeBSD, Juniper, Cisco / Network security articles and troubleshooting guides

FAQ
It is currently Wed Jan 18, 2017 7:39 pm


Mysql Application & Query Optimization, Questions, Indexes, Bugs.

Author Message
admin
Post  Post subject: Mysql> select records that have date/datetime column equal to today's date  |  Posted: Tue Nov 22, 2011 9:40 am
Site Admin

Joined: Mon Aug 03, 2009 8:43 am
Posts: 92

Offline
 

Mysql> select records that have date/datetime column equal to today's date

How to select rows from a mysql table containing multiple records, all of them having a datetime column.

Example mysql table:
Code:
mysql> select * from info;
+---------+---------------------+------------+
| id | upload_date    | ip    |
+---------+---------------------+------------+
|       1 | 2011-11-21 21:07:29 | 0123456789 |
|       2 | 2011-11-21 21:15:07 | 0123456789 |
|       3 | 2011-11-22 14:26:49 | 0123456789 |
+---------+---------------------+------------+
3 rows in set (0.00 sec)


Selecting rows with datetime column equal to today's date:
Code:
mysql> select * from info where date(upload_date) = date_sub(curdate(), interval 0 day);
+---------+---------------------+------------+
| id | upload_date    | ip    |
+---------+---------------------+------------+
|       3 | 2011-11-22 14:26:49 | 0123456789 |
+---------+---------------------+------------+
1 row in set (0.00 sec)


and, obviously, selecting all rows with one day before, use the "1 day" interval.

The mysql date() function is used on the table column because the column type is datetime (hour/min/second) and the date_sub() and curdate() functions are "date" functions.

_________________
VPSie - SSD VPS servers in AMS-IX, LINX, DE-CIX
https://vpsie.com





Top
Display posts from previous:  Sort by  
E-mail friendPrint view

Topics related to - "Mysql> select records that have date/datetime column equal to today's date"
 Topics   Author   Replies   Views   Last post 
There are no new unread posts for this topic. Mysql - Change position of a column after another column

admin

1

1447

Fri Oct 08, 2010 1:41 am

sonee4 View the latest post

There are no new unread posts for this topic. Mysql> how to store select Zulu / UTC timestamp in database

debuser

0

368

Fri Dec 16, 2011 5:23 am

debuser View the latest post

There are no new unread posts for this topic. Mysql: add column to table

debuser

1

1413

Fri Oct 08, 2010 1:38 am

sonee4 View the latest post

There are no new unread posts for this topic. Mysql change column's default value

debuser

0

870

Thu Aug 12, 2010 3:43 am

debuser View the latest post

There are no new unread posts for this topic. Mysql add Unique index to a table column

debuser

0

913

Fri Aug 06, 2010 10:01 am

debuser View the latest post

There are no new unread posts for this topic. Mysql remove column from an existing table

debuser

0

505

Fri Aug 06, 2010 10:06 am

debuser View the latest post

There are no new unread posts for this topic. How to calculate mysql time difference between unix timestamp column and now() format

mandrei99

0

3421

Fri May 31, 2013 4:10 am

mandrei99 View the latest post

There are no new unread posts for this topic. MySql doesn't start: libexec/mysqld: File './mysql-bin.index' not found (Errcode: 13)

debuser

0

879

Mon Feb 22, 2010 1:43 pm

debuser View the latest post

There are no new unread posts for this topic. Rename MySql table

debuser

1

390

Fri Oct 08, 2010 1:36 am

sonee4 View the latest post

There are no new unread posts for this topic. MySql rename table

admin

2

662

Mon Nov 28, 2011 3:39 am

Darwin View the latest post

 

Who is online
Users browsing this forum: No registered users and 0 guests
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:  
News News Site map Site map SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list


Delete all board cookies | The team | All times are UTC - 5 hours [ DST ]



phpBB SEO