omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    set values for picker.date ?

    Pythonista
    5
    5
    3403
    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.
    • AddledBadger
      AddledBadger last edited by

      Hi,
      Searched the docs and forums but can’t seem to find this. Any help on how to set a ui date picker to a particular value, rather than the current time as it’s displaying in my code at the moment. For example, 8am tomorrow.
      Thanks, Terry

      Phuket2 1 Reply Last reply Reply Quote 0
      • ramvee
        ramvee last edited by

        Hope this helps..

        # sets date time picker
        # you can get details of different parameters from strftime.org
        import datetime, ui
        date_picker = ui.DatePicker(bg_color=1)
        date_picker.mode = ui.DATE_PICKER_MODE_DATE_AND_TIME
        date_picker.date = datetime.datetime.strptime('01/03/1958-07:00:PM', '%d/%m/%Y-%I:%M:%p')
        date_picker.present()
        
        1 Reply Last reply Reply Quote 0
        • omz
          omz last edited by omz

          Here's a variant using parsedatetime for easy-to-read date parsing and math:

          import ui
          import parsedatetime
          cal = parsedatetime.Calendar()
          picker = ui.DatePicker(bg_color=1)
          picker.date = cal.parseDT('tomorrow 8am')[0]
          picker.present('sheet')
          
          1 Reply Last reply Reply Quote 1
          • coomlata1
            coomlata1 last edited by

            Try this.

            1 Reply Last reply Reply Quote 0
            • Phuket2
              Phuket2 @AddledBadger last edited by

              @AddledBadger , the beta version of Pythonista ships with module called arrow. Really simplifies date and time manipulation. If you are not on the beta version but have installed StaSH, you could pip install arrow yourself. Knowing that when the beta makes it to the App Store, arrow will be included.
              arrow docs
              StaSH

              Look this is not as easy as what the other guys suggest if you dont have arrow installed. I understand why they dont suggest it. Anyway, its another way.

              Anyway, the below is using arrow module.

              import ui
              import arrow
              
              dp = ui.DatePicker(bg_color='white')
              dp.mode = ui.DATE_PICKER_MODE_DATE_AND_TIME
              arr_date = arrow.get('2017-11-26 08:00:00', 'YYYY-MM-DD HH:mm:ss')
              dp.date = arr_date.datetime
              dp.present('sheet')
              
              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Powered by NodeBB Forums | Contributors