简体   繁体   中英

Search based on DateTime

I'm relatively new to ruby on rails. I do have a custom search form where I want to search with date and time. My database table does have a column with datetime as a datatype. I knew that we can extract date from Date(column name). I would like to know how to extract only time from datetime field. Please help me with this. Thanks in advance

Use date_format

mysql> select id, created_at from users limit 1;
+----+---------------------+
| id | created_at          |
+----+---------------------+
|  8 | 2009-08-19 09:24:24 |
+----+---------------------+
1 row in set (0.00 sec)

mysql> select id, DATE_FORMAT(created_at, "%h/%i/%s") from users limit 1;
+----+-------------------------------------+
| id | DATE_FORMAT(created_at, "%h/%i/%s") |
+----+-------------------------------------+
|  8 | 09/24/24                            |

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM