Check current date

Good afternoon,

I would like to know if you have how to check the current date (The correct date, not necessarily the date that the device shows) without internet connection … Does anyone have any idea how I can do this?

I’m not clear what you mean by ‘correct date, not necessarily the date that the device shows’

Without an internet connection you can get the date the device thinks it is and that is it. i.e. Whatever date and time the user has set on the device is all you have. 

With an internet connection I’m sure there is a way to get the current real date and time, but that is not what you asked for. 

See the various os.* options you have (all related): https://docs.coronalabs.com/api/library/os/index.html

Question: What are you using this for?  I ask because that might help with suggestions on solving the actual issue you’re addressing.

Firstly I apologize for the delay, I was bogged down with apps to finish and some bugs introduced me that took me several days to repair.

Now, what I’m trying to do is:
I have a SQL database and a PHP file hosted on a website. The corona connect with PHP, connects to SQL and gives me the result “FINAL DATE” which is the last date on which the device can use this application.
Only, to compare the end date, it uses the current date of the device. And my differential is that I require connection to the internet only the first time I use the application. However, over time, I can no longer require the internet to check whether the date shown on the device is true or not.

(Summarizing everything :slight_smile:
I have an end date and compare to the current date. If current date> end date then application for.

But, do you agree with me that to have this precision, I always need the true date? So I do not know how to do this =x

You have a two choices. 1. Trust the date on the local device. 2. Connect to the Internet and get the current time from an Internet time server. 

Rob

Oww … =(

As computers there is a “CPU Date” where it can never be changed (until it can, but it’s actually very difficult) I thought that for smartphones it also existed.

But OK. Thank you very much.

I think someone has been feeding you false info regarding desktop CPUs.  

Date info comes from a chip on the motherboard (MOBO) and requires a constant power-source (which is why all modern MOBOs have a battery) as well as a crystal oscillator to advance time.

CPUs don’t have circuitry dedicated to clocks or dates.  Likewise mobile CPUs don’t either.

Any Mac or PC can be fooled into thinking it is any date supported by the MOBO.

https://cs.stackexchange.com/questions/54933/how-do-computers-keep-track-of-time/54935

Can you provide a reference to this CPU date?  Google isn’t finding a good reference. I know there is a battery powered clock that all devices have that maintains the clock while powered off, but that date is no more “correct” than a date/time that can be set by the user. All clocks have drift and if that clock cannot be updated, it will eventually get off.

Mobile devices generally will have more accurate clocks because users change the clock far less than they do on PCs and those mobile devices all should be syncing their clocks from WiFi or the cell phone tower. Most modern PC operating systems should also be syncing time from a network resource when they can be connected.

Rob

Not wanting to seem like I didn’t want to help, because I do… :slight_smile:

  1. You’re going to have to rely on whatever time the device says it is, BUT

  2. You can also easily implement code that detects if the user’s device suddenly ‘goes back in time’.

That is, you can simply keep a file with the date and time the app started up on each run/resume.  Then, look at that info and if you detect a newly stored date is before a previously stored date (and time), you can do ‘something’.

What that ‘something’ is, is up to you.  i.e. If you want to disable the service go for it.  Of you can pop up a dialog and tell the user you detected the date/time irregularity.  You can also say, if this is detected again, the feature you’re protected will be disabled.

I’m not clear what you mean by ‘correct date, not necessarily the date that the device shows’

Without an internet connection you can get the date the device thinks it is and that is it. i.e. Whatever date and time the user has set on the device is all you have. 

With an internet connection I’m sure there is a way to get the current real date and time, but that is not what you asked for. 

See the various os.* options you have (all related): https://docs.coronalabs.com/api/library/os/index.html

Question: What are you using this for?  I ask because that might help with suggestions on solving the actual issue you’re addressing.

Firstly I apologize for the delay, I was bogged down with apps to finish and some bugs introduced me that took me several days to repair.

Now, what I’m trying to do is:
I have a SQL database and a PHP file hosted on a website. The corona connect with PHP, connects to SQL and gives me the result “FINAL DATE” which is the last date on which the device can use this application.
Only, to compare the end date, it uses the current date of the device. And my differential is that I require connection to the internet only the first time I use the application. However, over time, I can no longer require the internet to check whether the date shown on the device is true or not.

(Summarizing everything :slight_smile:
I have an end date and compare to the current date. If current date> end date then application for.

But, do you agree with me that to have this precision, I always need the true date? So I do not know how to do this =x

You have a two choices. 1. Trust the date on the local device. 2. Connect to the Internet and get the current time from an Internet time server. 

Rob

Oww … =(

As computers there is a “CPU Date” where it can never be changed (until it can, but it’s actually very difficult) I thought that for smartphones it also existed.

But OK. Thank you very much.

I think someone has been feeding you false info regarding desktop CPUs.  

Date info comes from a chip on the motherboard (MOBO) and requires a constant power-source (which is why all modern MOBOs have a battery) as well as a crystal oscillator to advance time.

CPUs don’t have circuitry dedicated to clocks or dates.  Likewise mobile CPUs don’t either.

Any Mac or PC can be fooled into thinking it is any date supported by the MOBO.

https://cs.stackexchange.com/questions/54933/how-do-computers-keep-track-of-time/54935

Can you provide a reference to this CPU date?  Google isn’t finding a good reference. I know there is a battery powered clock that all devices have that maintains the clock while powered off, but that date is no more “correct” than a date/time that can be set by the user. All clocks have drift and if that clock cannot be updated, it will eventually get off.

Mobile devices generally will have more accurate clocks because users change the clock far less than they do on PCs and those mobile devices all should be syncing their clocks from WiFi or the cell phone tower. Most modern PC operating systems should also be syncing time from a network resource when they can be connected.

Rob

Not wanting to seem like I didn’t want to help, because I do… :slight_smile:

  1. You’re going to have to rely on whatever time the device says it is, BUT

  2. You can also easily implement code that detects if the user’s device suddenly ‘goes back in time’.

That is, you can simply keep a file with the date and time the app started up on each run/resume.  Then, look at that info and if you detect a newly stored date is before a previously stored date (and time), you can do ‘something’.

What that ‘something’ is, is up to you.  i.e. If you want to disable the service go for it.  Of you can pop up a dialog and tell the user you detected the date/time irregularity.  You can also say, if this is detected again, the feature you’re protected will be disabled.