哪个MySQL数据类型用于调度? [英] Which MySQL data type to use for scheduling?

查看:125
本文介绍了哪个MySQL数据类型用于调度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想记录在电影院播放的电影的开始和结束时间。我需要存储日期(例如2011年1月1日),开始时间(例如上午9:00)和结束时间(例如上午11点)。我应该使用DateTime吗?我看到一些实现,其中INT用于表示分钟的时间(例如,0 = 12午夜,1 = 12:01上午等)。

I want to record the start and end times of, say, movies playing at the cinemas. I need to store the date (e.g. Jan 1, 2011), start time (e.g. 9:00am), and end time (e.g. 11am). Should I used DateTime? I've seen some implementations wherein an INT is used to represent time in minutes (e.g. 0 = 12 midnight, 1 = 12:01am, etc.). I'm not sure if there is some sort of benefit to using INT over DateTime.

建议?

编辑1:

如上所述扩展使用INT的想法,表格可能会包含以下列:

Expanding on the idea of using INT as described above, the table would probably have the following columns:


  • 日期(例如2011年1月1日)

  • start_time(例如540 - 表示上午9点)

  • end_time(例如660 - 表示上午11点)

推荐答案

a href =http://dev.mysql.com/doc/refman/5.1/en/datetime.html =nofollow> DATETIME 或 INT

Use DATETIME or INT

我喜欢存储日期和时间在unix时间戳(INT),因为我可以在PHP函数中使用它 date

I prefer to store date&time in unix timestamp (INT), because i can use it in PHP functions like date

echo "Movie will start at ".date("H:i", $row['start_time']);

它很容易操作:

echo "Movie will start in ".(time() - $row['start_time'])." seconds";

当前日期和时间: http://www.unixtimestamp.com/

如果您要将电影复制到第二天:

If you want to copy movies to next day:

 $sql = "SELECT * FROM movies WHERE start_time >= ".strtotime("today 00:00")." AND start_time <= ".strtotime("today 23:59");

 // query..
 foreach($results as $row) {
    $new_start = strtotime("+1 day", $row['start_time'];    
    // insert
 }

这篇关于哪个MySQL数据类型用于调度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆