mysql中时间的储存方式,哪种方法在MySQL中存储日期和时间更好?

i would like to store the date and time in the following format in the database

a) DD-MM-YYYY or i could add up HH-MM

b) as my servers are located in US i would like to fetch the time as per IST. now that will be GMT : +5:30

earlier i used to store the date in mysql in this format timestamp(int(11)):1291746600. i used to convert the date with strtotime();

currently my intention of storing the date is just to store and display. in the future i would like to calculate the no. of days, months etc.

which would be the best possible solution for this?

P:S : i would appreciate if someone could explain me which datatype to use and how to use it with PHP.

解决方案

Use DATETIME fields! They are the best format to store dates in mySQL. They offer proper indexing and optimization, and you can use the full range of mySQL's date functions.

Any specific format you need to output the fields in, you can create from a DATETIME field using DATE_FORMAT().

MySQL doesn't support time zones in DATETIME fields - you will usually set a global time zone on the server and use that.

There's good related reading on Timezones in these questions:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值