mysql資料庫中關於時間的比較

2021-06-28 15:57:18 字數 723 閱讀 8599

問題背景;

1、影片開始時間大於當前時間不足15分鐘時為暫停購票

超過15分鐘即可購票

解決方案:

starttime為varchar型別:str_to_date(starttime,'%y-%m-%d %h:%i:%s')轉變為date型別

mysql查詢語句:

select (unix_timestamp(str_to_date(starttime,'%y-%m-%d %h:%i:%s'))-unix_timestamp(now())) as "ss",screencode,starttime 

from ec_movie_planinfo 

where (unix_timestamp(str_to_date(starttime,'%y-%m-%d %h:%i:%s'))-unix_timestamp(now()))>15*60  

unix_timestamp()將時間轉換為時間戳,兩者相減得到兩個時間之間的秒數

2、mysql語句的時間格式化

解決方案:

date_format(date,format)函式,而format的格式可以為:%y-%m-%d,但是寫成『yyyy-mm-dd』就不行

所以'%y-%m-%d %h:%i:%s'-----》『yyyy-mm-dd hh:mm:ss』

'%y-%m-%d'----》『yyyy-mm-dd』

關於MySQL資料庫如何按時間查詢

這裡做了幾個測試 select from simingpai where timestamp createtime 2015 9 6 select from simingpai where timestamp createtime 2015 9 6 00 00 00 select from simi...

關於Mysql資料庫

1 首先從mysql儲存引擎說起 什麼是儲存引擎呢?在mysql中 儲存引擎是指儲存mysql資料表的不同的儲存技術 這樣可以滿足不同的業務需求 常見的mysql儲存引擎 儲存技術 innodb memory myisam 2 innodb的特點 支援事務 支援外來鍵 支援自動增長列 優點 提供良好...

關於MySQL資料庫

mysql最流行的關係型資料庫管理系統 mysql官網 mysql是web應用方面最好的rdbms應用軟體之一 rdbms relational database management system關聯式資料庫管理系統 問 什麼是資料庫?答 資料庫 database 是按照資料結構來組織 儲存和管理...