Storing a date as a 32 bit integer

I (think I) have a requirement to store a date yyyy:MM:dd:HH:mm:ss within the bounds of a 32 bit integer that I can send to an arduino and send back again as a integer and then translate back to the date code yyyy:MM:dd:HH:mm:ss.

In simple terms I could format it as yyMMddHHmmss and then simply segment it back out. However, there's 12 digits which would exceed the 10 digits of uint_32t.

I could drop the yyyy and it would only ever be a problem if I was using the app across midnight on 31st December.

Am I thinking too hard about this and does App Inventor have a native way it stores dates to the detail of yyyy:MM:dd:HH:mm:ss within the limits of uint32_t?

use Clock.GetMillis block, you will get a number with 13 digits, remove the last 3 digits (millis), you will get a 10 digits.
And also, you can format this number to yyyy:MM:dd HH:mm:ss easily.

yyyy:MM:dd:HH:mm:ss is 19bytes (ASCII), so you could send it as-is to Arduino via Bluetooth.

Yes, I could, but I have set up a fairly non-forward-thinking parsing system on the arduino side. I could redevelop it, but right now I'm trying to work with 32 bit integers.

Thanks @Kevinkun

I smashed out this code to understand your suggestion:
blocks (45)
blocks (46)

Which resulted in:
image

Seems to be exactly what I need.

Thanks again.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.