How to get the difference between two timestamps in seconds

You could use the TIMEDIFF() and the TIME_TO_SEC() functions as follows: SELECT TIME_TO_SEC(TIMEDIFF(‘2010-08-20 12:01:00’, ‘2010-08-20 12:00:00’)) diff; +——+ | diff | +——+ | 60 | +——+ 1 row in set (0.00 sec) You could also use the UNIX_TIMESTAMP() function as @Amber suggested in an other answer: SELECT UNIX_TIMESTAMP(‘2010-08-20 12:01:00’) – UNIX_TIMESTAMP(‘2010-08-20 12:00:00’) diff; +——+ | … Read more

MySQL convert date string to Unix timestamp

Here’s an example of how to convert DATETIME to UNIX timestamp: SELECT UNIX_TIMESTAMP(STR_TO_DATE(‘Apr 15 2012 12:00AM’, ‘%M %d %Y %h:%i%p’)) Here’s an example of how to change date format: SELECT FROM_UNIXTIME(UNIX_TIMESTAMP(STR_TO_DATE(‘Apr 15 2012 12:00AM’, ‘%M %d %Y %h:%i%p’)),’%m-%d-%Y %h:%i:%p’) Documentation: UNIX_TIMESTAMP, FROM_UNIXTIME

MySQL datetime fields and daylight savings time — how do I reference the “extra” hour?

I’ve got it figured out for my purposes. I’ll summarize what I learned (sorry, these notes are verbose; they’re as much for my future referral as anything else). Contrary to what I said in one of my previous comments, DATETIME and TIMESTAMP fields do behave differently. TIMESTAMP fields (as the docs indicate) take whatever you … Read more

Pandas Timedelta in Days

Using the Pandas type Timedelta available since v0.15.0 you also can do: In[1]: import pandas as pd In[2]: df = pd.DataFrame([ pd.Timestamp(‘20150111’), pd.Timestamp(‘20150301’) ], columns=[‘date’]) In[3]: df[‘today’] = pd.Timestamp(‘20150315’) In[4]: df Out[4]: date today 0 2015-01-11 2015-03-15 1 2015-03-01 2015-03-15 In[5]: (df[‘today’] – df[‘date’]).dt.days Out[5]: 0 63 1 14 dtype: int64

Getting date format m-d-Y H:i:s.u from milliseconds

You can readily do this this with the input format U.u. $now = DateTime::createFromFormat(‘U.u’, microtime(true)); echo $now->format(“m-d-Y H:i:s.u”); This produces the following output: 04-13-2015 05:56:22.082300 From the PHP manual page for date formats: U = Seconds since the Unix Epoch u = Microseconds http://php.net/manual/en/function.date.php Thanks goes to giggsey for pointing out a flaw in my … Read more

How to convert integer timestamp into a datetime

datetime.datetime.fromtimestamp() is correct, except you are probably having timestamp in miliseconds (like in JavaScript), but fromtimestamp() expects Unix timestamp, in seconds. Do it like that: >>> import datetime >>> your_timestamp = 1331856000000 >>> date = datetime.datetime.fromtimestamp(your_timestamp / 1e3) and the result is: >>> date datetime.datetime(2012, 3, 16, 1, 0) Does it answer your question? EDIT: … Read more

git rebase without changing commit timestamps

Update June 2014: David Fraser mentions in the comments a solution also detailed in “Change timestamps while rebasing git branch“, using the option –committer-date-is-author-date (introduced initially in Jan. 2009 in commit 3f01ad6 Note that the –committer-date-is-author-date option seems to leave the author timestamp, and set the committer timestamp to be the same as the original … Read more

How to convert integer timestamp to Python datetime

datetime.datetime.fromtimestamp() is correct, except you are probably having timestamp in miliseconds (like in JavaScript), but fromtimestamp() expects Unix timestamp, in seconds. Do it like that: >>> import datetime >>> your_timestamp = 1331856000000 >>> date = datetime.datetime.fromtimestamp(your_timestamp / 1e3) and the result is: >>> date datetime.datetime(2012, 3, 16, 1, 0) Does it answer your question? EDIT: … Read more