/    Sign up×
Community /Pin to ProfileBookmark

Truncating Dates

I have a variable that is holding a date object and I have another variable that is entered by a user which has been converted into date format.

I am having problems Date checking because todays date is holding a time as well and not the time from midnight. below is roughly the code…

[code]
var todaysDate = new Date();
var enteredDate; // has been set

if (enteredDate < todaysDate) {
alert(“The date must be today or in the future.”);
return false;
}
[/code]

If the dates are the same then it is passing so I need to truncate the todaysDate. I did todaysDate.setTime(0) but it sets it to 1970.

How do you do this?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@fredmvMay 24.2004 — I believe what you're looking for is either the [font=courier]getTime[/font] or [font=courier]valueOf[/font] methods of the [font=courier]Date[/font] object.
Copy linkTweet thisAlerts:
@ellisd5authorMay 24.2004 — Nope its not it, Those 2 methods are returning the dates in miliseconds or something else, one needs truncating. Im sure I have done it before by

[b]set????(0, 0, 0, 0)[/b]
×

Success!

Help @ellisd5 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.25,
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,
)...