Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    To get week-number from a date

    Scheduled Pinned Locked Moved LoPy
    9 Posts 5 Posters 63 Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      StefanoF
      last edited by

      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

      T K 2 Replies Last reply Reply Quote 0
      • G Offline
        Gijs
        last edited by

        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 like import datetime. This will be similar to the datetime Python library.

        S 1 Reply Last reply Reply Quote 1
        • T Offline
          Thierry @StefanoF
          last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • S Offline
            StefanoF @Gijs
            last edited by

            @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...

            rcolisteteR 1 Reply Last reply Reply Quote 0
            • G Offline
              Gijs
              last edited by

              Sorry, I did not notice that!
              You could take a look at how they create the weeknumber and copy only that part.
              Best,
              Gijs

              1 Reply Last reply Reply Quote 0
              • rcolisteteR Offline
                rcolistete @StefanoF
                last edited by

                @StefanoF Use frozen modules, building your firmware for LoPy v1.

                My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).

                1 Reply Last reply Reply Quote 0
                • K Offline
                  kjm @StefanoF
                  last edited by

                  @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

                  G 1 Reply Last reply Reply Quote 0
                  • G Offline
                    Gijs @kjm
                    last edited by

                    @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

                    K 1 Reply Last reply Reply Quote 1
                    • K Offline
                      kjm @Gijs
                      last edited by

                      @Gijs Ask me again new year's day!

                      1 Reply Last reply Reply Quote 1

                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                      With your input, this post could be even better 💗

                      Register Login
                      • 1 / 1
                      • First post
                        Last post

                      Pycom on Twitter

                      Pycom