/    Sign up×
Community /Pin to ProfileBookmark

checking with Date

Hello Forum

I m using web form where visitor will use 3 drop down boxes to choose Date/month/year – i m getting data in dd/mm/yyyy format; i want to check the date with the current date.. i m using the following function but i m not getting exact comparision..

<script language = “javascript”>
function dtchk()
{
var d = new Date();
var dtoday = d.getDate();
var dmonth = d.getMonth();
var dyear = d.getYear();

var selcDt = document.frm.dt.options[document.frm.dt.selectedIndex].value;
var selcMth = document.frm.mth.options[document.frm.mth.selectedIndex].value;
var selcYr = document.frm.yr.options[document.frm.yr.selectedIndex].value;

var selcDate = selcDt + “/” + selcMth + “/”+ selcYr;
var sysDate = dtoday + “/” + (dmonth+1) + “/” + dyear;

if ( selcDate.valueOf() < sysDate.valueOf())
{
//alert (“Selected Date : ” + selcDate.valueOf());
//alert (“System Date : ” + sysDate.valueOf());
alert(“Please select appointment date advance from todays date”);
document.frm.dt.focus();

return false;
}
} // function end
</script>
<select name=”dt” onchange=”dtchk();” class=”txtbx”>

is there any way to convert the string into date (dd/mm/yyy) so it can be checked properly… or any other solution for it..

thanks in advance

saifee

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@CharlesMay 19.2005 — Your better bet is to go the other way. Something likefunction checkData (form) {return new Date () == new Date (form.yr.optons[form.yr.selectedIndex].value, form.mth.options[form.mth.selectedIndex].value - 1, form.dt.options[form.dt.selectedIndex].value)}
Copy linkTweet thisAlerts:
@saifeeauthorMay 21.2005 — Hi Charles..

Little Confusion with the code..

How will i pass data in this function??

How do i check the return value???

thanks

Saifee
Copy linkTweet thisAlerts:
@BigMoosieMay 21.2005 — ...
Copy linkTweet thisAlerts:
@Orc_ScorcherMay 21.2005 — function dtchk()
{
var form = document.frm
var nowInMs = +new Date
var selectedDateInMs = +new Date(
form.yr.options[form.yr.selectedIndex].value,
form.mth.options[form.mth.selectedIndex].value - 1,
form.dt.options[form.dt.selectedIndex].value)

<i> </i>if (selectedDateInMs &lt; nowInMs)
<i> </i>{
<i> </i> alert("Please select appointment date advance from todays date")
<i> </i> form.dt.focus()
<i> </i>}
}
Copy linkTweet thisAlerts:
@saifeeauthorMay 23.2005 — Thanks for the nice code snippet.. its solves purpose..

want to ask one query..

as u have wrote in code..

var nowInMs = +new Date();

what does this mean??? +new date();

i have seen the value of this variable but couldnt understand it.. if u can explain me...

thank you

saifee
Copy linkTweet thisAlerts:
@BigMoosieMay 23.2005 — the + is optional, its like 5 = +5
Copy linkTweet thisAlerts:
@Orc_ScorcherMay 23.2005 — '+new Date()' is a shortcut for 'new Date().valueOf()'.
×

Success!

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