how to get the real current date?

Hi All,

How can I get the current date (the real current date and not the computer one) to compare it with a fixed date ?
Thanks in advance !

Graud Bousquet (KnotsBag, SeamlessMaker…)

[code]Dim d As New Date
d.Year = 2012
d.Month = 12
d.Day = 5

Dim today As New Date // How can I change this line to obtain the real current date ???

If d < today Then
MsgBox(“That’s before today!”)
End If

If d > today Then
MsgBox(“That’s after today!”)
End If

If d = today Then
MsgBox(“That’s today!”)
End If[/code]

You’d need to grab it from one of the time servers on the internet then.

Thanks Norman but how can I write a simple code line to grab it ? I write desktop app and I’m a newbie with web code ! (I have the desktop edition of Xojo)
Thanks again !


Why can’t you use the computer’s date?

Ah - not sure that anyone has currently built an SNTP client in Xojo (or ever that I can find) - SNTP is Simple Network Time Protocol and probably fits your needs

Oddly enough even SNPT isn’t really “simple”
It involves implementing & adhering to the protocol and querying a well known reliable server.

I have yet to see an acronym with “simple” in it that actual is! :slight_smile:

Depending on the purpose/need of the “real” date/time, couldn’t you find a website that posts the current time/date and then parse that? Sort of a cheap hack, but might be easier. Still wouldn’t help for knowing your actual location, though.

Since all modern computers have their time/date set via the Internet anyway, I don’t see why this would be needed.

Forgive me if this code is a mess… I wrote it eons ago :slight_smile:

NTP Example

what about a SOAP service eg

Since all modern computers have their time/date set via the Internet anyway, I don’t see why this would be needed.

On my computer, this is user changeable.

Also, my computer is not connected to the internet 24/24 (nor 7/7 nor 12/12 nor…).

I also found computers whose ‘clock battery’ was without power; the computer clock is reset to an old date at each Power On (if Power is with a On/Off socket).

Not sure what kind of app the OP is working on but I have a time clock app that our employees use. I didn’t want to rely on the date/time of the PC the employee was using to clock in or out as it could be altered. I query the date/time from the database server. I keep the server date/time updated with a PERL script.

Hi all,

For example it’s to limit the duration of a demo mode ! A lot of demo mode can be bypassed by changing the computer date !

Greg : thanks for sharing your code but nothing happens when I click on the “Go” button ???
I use Xojo R2 on MacBook Pro MacOSX 10.6.8

Thanks !


I had no success with Greg’s code, either. It seems that the DataAvailable event does not fire.

Interesting. It works here :slight_smile:

Keep in mind that NTP requires port 37 to be open for outgoing connections, so it could be that. Also, it could be that the time server isn’t reachable. I can’t remember if its set to or

It’s and it works fine for me on OS X 10.8.4

It works okay for me too but seems to take a few clicks of the button - I haven’t looked at it in any details to know why.

It works for me too , but it takes several clicks on the “go” button,. The number of clicks sems to be random (?) Sometimes 2, sometimes 4…
MacBookPro MacOSX 10.6.8 Xojo R2

Thanks Greg and Gavin !

When I tried it yesterday I needed to change the SNTP server to and then it worked perfectly. You can check for availability, if you are going to implement a SNTP solution and want to make it more reliable you may want to walk down a list of servers until you got a response.

A query on this, if you will.

I have a need to produce two audio files, on two different places, and to tag their times in a way they can be reliably lined up later on.

I have two problems. One is that audio recording may not start at the same time. The other is that audio recording may drift from one computer to the other. This is usually unnoticeable (a couple of seconds over an hour, for example) and happens due to each computers capabilities, load, write speed, etc. The problem is that this drift is very obvious when the two files are aligned.

I was thinking of using NTP to tag both the beginning and end of the recording, that way I’d solve both issues simultaneously. Before I embark on this I’d rather ask if you guys have alternatives that I could use.

Keep in mind that using the local computer’s time is not good enough, as both might not be aligned, and the resolution needed to avoid drift must go down to at least tenths or hundredths of a second for the duration.

Any suggestions or is NTP really my only choice?

This isn’t modern NTP - it’s the old timeserver on port 37

You can get the more accurate network time down to 1/10,000’s of a second but it’s a bit more complex.

There is some php code on the following URL which does the more accurate request, you would need to port it over to Xojo :

It needs modifying slightly to get it working due to the cookie stuff they use but when I tested it I got an output accurate to 1/10,000th of a second like this :

NTP time: 2013-10-25 22:27:11.7583

There’s a lot more to NTP that you might think - it takes into account the round trip of the network request instead of just issueing a single time so it sends back a bunch of bytes which need interpreting correctly.

More info here :

There’s an even more accurate version than this available as well. I thought the fractions of a second on the most accurate version could be a good source of entropy.

[quote=28881:@GraudBOUSQUET]For example it’s to limit the duration of a demo mode ! A lot of demo mode can be bypassed by changing the computer date !


A web app should have accurate time, as it executes on a host that is usually synchronized over the Internet.

I have a web app for customers to download during a given period of time. Upon sale I create a file where I record the customer details, and TotalSeconds. Then all I have to do is compare with current TotalSeconds, each day represents 86400 seconds. An I do not have to compare “real time”…