Python Forum
How to convert different timestamp formats?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to convert different timestamp formats?
#11
(Aug-05-2019, 05:56 PM)buran Wrote:
(Aug-05-2019, 05:54 PM)python_newbie09 Wrote: timestamp has a different encoding compared to the first one and that's what I am trying to figure out now. They are matlab files and it's really painful with these files somehow being saved with different encodings
encoding is something different and it has nothing to do with timestamp format.

Okay, so when I used the script below in matlab, I am getting a more appropriate timestamp

t = datetime(42737.614433,'ConvertFrom','excel')

t =

datetime

02-Jan-2017 14:44:47

So it has something to do with the file being recorded in excel before saving as a matlab file, i guess

(Aug-05-2019, 06:00 PM)python_newbie09 Wrote:
(Aug-05-2019, 05:56 PM)buran Wrote: encoding is something different and it has nothing to do with timestamp format.

Okay, so when I used the script below in matlab, I am getting a more appropriate timestamp

t = datetime(42737.614433,'ConvertFrom','excel')

t =

datetime

02-Jan-2017 14:44:47

So it has something to do with the file being recorded in excel before saving as a matlab file, i guess

in python, i have to use the code below to get the same result.

t = pd.to_datetime('1899-12-30') + pd.to_timedelta(42737.614433,'D')
Reply
#12
in excel epoch is 1 January 1900, i.e. the whole number is days after 31.12.1899
the reason why you need to add 30 December 1899, not 31st is an known error in excel - Excel incorrectly assumes 1900 is a leap year (actually it was error in Lotus 1-2-3 and was kept in excel for compatibility)
https://support.microsoft.com/en-us/help...-leap-year

so you need to distinguish between the two. If you don't know in advance it makes sense to make conversion, then test if the result year is greater than some year (e.g. 2000) and apply different conversion if not.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#13
(Aug-05-2019, 06:36 PM)buran Wrote: in excel epoch is 1 January 1900, i.e. the whole number is days after 31.12.1899
the reason why you need to add 30 December 1899, not 31st is an known error in excel - Excel incorrectly assumes 1900 is a leap year (actually it was error in Lotus 1-2-3 and was kept in excel for compatibility)
https://support.microsoft.com/en-us/help...-leap-year

so you need to distinguish between the two. If you don't know in advance it makes sense to make conversion, then test if the result year is greater than some year (e.g. 2000) and apply different conversion if not.

thanks a lot. I will change it accordingly. thanks for the patience
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Excel from SAP - dealing with formats and VBA MasterOfDestr 7 551 Feb-25-2024, 12:23 PM
Last Post: Pedroski55
  error in timestamp Led_Zeppelin 3 3,205 Jun-15-2022, 08:28 PM
Last Post: deanhystad
  error in timestamp Led_Zeppelin 0 1,006 Jun-10-2022, 07:59 PM
Last Post: Led_Zeppelin
Thumbs Up Convert ActiveDirectory timestamp into regular one. Arrow (solved) SpongeB0B 2 1,928 Nov-02-2020, 08:34 AM
Last Post: bowlofred
  [split] NameError: name 'formats' is not defined shobhu123 1 3,974 May-24-2020, 06:29 PM
Last Post: Skaperen
  Need help working with two excel file with different formats mikey3580 1 1,601 Apr-22-2020, 07:11 AM
Last Post: DPaul
  Timestamp is undefined ErnestTBass 7 7,935 Feb-16-2019, 08:27 PM
Last Post: snippsat
  How to generate calendar with 2 formats in python luizcrf 1 2,665 Nov-01-2018, 06:46 AM
Last Post: Larz60+
  timestamp not updating bowen73 3 7,183 Aug-20-2017, 11:13 PM
Last Post: bowen73
  matplotlib timestamp zero_shubh0 2 6,807 Dec-02-2016, 02:12 PM
Last Post: zero_shubh0

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020