开发者

convert datetime to timeticks in php and mysql

i want to convert datetime.now() to ticks, like is the time is 4:00 PM on june 18th 2010开发者_开发技巧, i want it to be 20100618160000, or some complex number like this. I want to use this number and another field in my database as the primary keys combination to retrieve data. I am using php and mysql so it would be very helpful if someone could send me some code for the same. Thanks.

SJ


Use strtotime to parse any string representation of a date and time into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC)

http://us2.php.net/manual/en/function.strtotime.php


SELECT UNIX_TIMESTAMP();


I want to use this number and another field in my database as the primary keys combination to retrieve data.

Probably not a good idea. There is the theoretical possibility of a collision when two instances of your script get called at the exact same time. You would have to combine this with another unique value to create a safe primary key.

But to answer your question, microtime(true) will give you the current timestamp with microseconds as one long number. strtotime() will translate about any american-format time into a time stamp.


You can use number_format(($time * 10000000) + 621355968000000000 , 0, '.', ''); where $time represents the the unix timestamp value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜