Mysql query Timestamp and date conversion are used in the database. It is often necessary to query records by specified date to facilitate statistics. In the database, many of them store timestamps, some directly store dates, which may not be so easy to query. mysql provides two functions: from_unixtime (time_stamp)
Mysql query Timestamp and date conversion are used in the database. It is often necessary to query records by specified date to facilitate statistics. In the database, many of them store timestamps, some directly store dates, which may not be so easy to query. mysql provides two functions: from_unixtime (time_stamp)-converts a timestamp to a date unix_ti
Mysql query Timestamp and date conversion
In the use of the database, you often need to query records by specified date for statistics. In the database, many of them store timestamps,
Some directly store dates, which may not be so easy to query.
Mysql provides two functions:
From_unixtime (time_stamp)-> convert a timestamp to a date
Unix_timestamp (date)-> converts a specified date or date string to a timestamp
For example: from_unixtime (time_stamp)
select from_unixtime(1382544000);+---------------------------+| from_unixtime(1382544000) |+---------------------------+| 2013-10-24 00:00:00 |+---------------------------+
For example, unix_timestamp (date)
select unix_timestamp(date('2013-10-24'));+------------------------------------+| unix_timestamp(date('2013-10-24')) |+------------------------------------+| 1382544000 |+------------------------------------+
If you want to query the order records for the current day:
select count(*) from b_order Where date_format(from_unixtime(create_time),'%Y-%m-%d') = date_format(now(),'%Y-%m-%d')
You can also do this:
select count(*) from b_order Where create_time >= unix_timestamp('2013-10-24 00:00:00') and create_time <= unix_timestamp('2013-10-24 23:59:59') ;