Page 1 of 1

datetime string convert to datetime

Posted: Sat Jan 08, 2022 8:11 am
by KLF
Good morning everyone,

how is it possible to convert a dateime string into datetime format in micropython?
I would like to compare an actual timestamp with a timestamp priveous stored in string format.
How is that possible in micropython if datetime is not available?

In Python it is possible like this:

Code: Select all

from datetime import datetime

datetime_string = '01/08/22 10:47:26'

datetime_object = datetime.strptime(datetime_string, '%m/%d/%y %H:%M:%S')

print(datetime_object)
Thanks a lot for any help

Re: datetime string convert to datetime

Posted: Sat Jan 08, 2022 11:41 am
by KLF
Hi everyone,

it seems that I have to go via Seconds since 1.1.2000 and then compare the integer values.
That works (not based on seconds, but based on minutes - don't know why, but it's close enough for me)

Best regards
Klaus

Re: datetime string convert to datetime

Posted: Sun Jan 09, 2022 8:59 pm
by lorcap
If you don't mind experimental code, you can try out my datetime branch. It's stable from my point of view: it's just waiting for a PR merging. You can find the doc too.

Re: datetime string convert to datetime

Posted: Mon Jan 10, 2022 4:18 pm
by KLF
Hi lorcap,

this library sounds very interesting.
But in folder: upy-micropython-lib-datetime\upy-micropython-lib-datetime\micropython
I can't find anything regarding your datetime description.
Is your description really related to MICRO-Python?

best regards
Klaus

Re: datetime string convert to datetime

Posted: Mon Jan 10, 2022 8:18 pm
by lorcap
You're right, the directory structure may not be obvious to non-developers. My contribution is in this folder.

PS: yes, it's related to MicroPython.

Re: datetime string convert to datetime

Posted: Tue Jan 11, 2022 8:36 am
by KLF
Good morning lorcap,

thanks a lot for your tip.
I did not expect it in that folder, because there is a micropython folder available and the folder you gave me is a subfolder of python-stdlib.
So I thought python-stdlib is not defined for micropython.

best regards
Klaus