To get week-number from a date
-
Hi,
how I do it, get week-number from a date on micropython?
I'used utime but not found!
Somebody kindly can help me?Many thank
-
@Gijs Ask me again new year's day!
-
@kjm But will that always work though? I have a feeling this might break in some edge cases (week 53, new year week not starting on monday) or is that just in my head?
Gijs
-
@StefanoF You could try time.localtime()[7] which gives you day of the year then calculate week number from that? For example
week_number=int(time.localtime()[7]/7)
should give weeks 0-51
-
@StefanoF Use frozen modules, building your firmware for LoPy v1.
-
Sorry, I did not notice that!
You could take a look at how they create the weeknumber and copy only that part.
Best,
Gijs
-
@Gijs said in To get week-number from a date:
import datetime
Hi Giijs , Many thanks, I not can't writting on lopy 73kb it's very big...
-
This post is deleted!
-
It is indeed not built in by default.
I suggest you look at something like this? https://github.com/micropython/micropython-lib/blob/master/datetime/datetime.py. You can upload this in the lib folder and include it likeimport datetime
. This will be similar to the datetime Python library.