/    Sign up×
Community /Pin to ProfileBookmark

Get today date on the Server

I have one web-page on the web-site & I would like to detect a select date isn’t in the past, so I use:

var date_today = new Date();

It works well, except if I (or other user) changing the System Time of the computer to the past, I discover that the [B]date_today [/B]is actually that date … therefore my detection is wrong!

I would like to use the today date of the Server where my web-page located … so that I don’t concern about local system date any more

Any java code to get today date on the Server?

Thank to any help

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Jun 29.2010 — As long as you have a server-side language to supply the time that is no problem with [url=http://www.w3schools.com/ajax/default.asp]AJAX[/url]. You'll have to see what language is supported on your server, probably PHP, Perl, ASP, even SSI includes support time I think.
Copy linkTweet thisAlerts:
@xeteaJun 29.2010 — You probably want to do it with PHP or ASP, not Java. I don't know how to do it with ASP, but in PHP you can use the date() function. Read the manual here:

http://php.net/manual/en/function.date.php

This will send the current date in the format 2010-06-30 to the client.
[code=php]
<?php

echo date("Y-m-d");

?>
[/code]


NOTE: You might also want to set the server timezone, if you're using a server in a different timezone than the one you're in. In that case the above code would look like this:

[code=php]
<?php

date_default_timezone_set("Europe/Stockholm");
echo date("Y-m-d");

?>
[/code]
Copy linkTweet thisAlerts:
@NewComer2009authorJun 30.2010 — Unfortunately, I have never used php, also this today_verification is in javasript section (after the SUBMIT button action) ... but thank for help :o
Copy linkTweet thisAlerts:
@xeteaJun 30.2010 — You're welcome. But it is impossible to get the date from the server without using server-side code. Javascript is client-side, so you can't get the server date with only javascript. (as Declan said, while I was writing my previous post)
Copy linkTweet thisAlerts:
@NewComer2009authorJun 30.2010 — Your latest explanation is clear for me, in this case I can use a trick to get Server DateTime with ASP first, then use javascript verify its reference later!

Thank for help again, it really solve my issue ?
Copy linkTweet thisAlerts:
@sohguanhJun 30.2010 — You probably want to do it with PHP or ASP, not Java. [/QUOTE]

I am curious why you say "not Java" ? Basically any programming language that has an API to retrieve current date will do fine. Even if we use C, C++, Python we still can get it, format display(if needed) and return back to the client.
Copy linkTweet thisAlerts:
@xeteaJun 30.2010 — I am curious why you say "not Java" ? Basically any programming language that has an API to retrieve current date will do fine. Even if we use C, C++, Python we still can get it, format display(if needed) and return back to the client.[/QUOTE]
Well, that's true. But it's quite rare to use Java for these sort of tasks. Different languages focus on different things and PHP, ASP, etc was made for exactly this purpose. Most servers aren't configured to run Java-applications and return the output from them to the client. So that's why I said he probably wan't to use PHP or ASP and not Java. Maybe I should have skipped the "not Java" part, but I guessed that he/she didn't know that much about server-side code (no offense) and I was simply trying to hint a direction for further studies to learn that. And Java is not the simplest way to accomplish what was trying to be done here.
×

Success!

Help @NewComer2009 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...