get/format date field

P

peashoe

I have an asp page that uses a calendar.js (pop-up) file to add an
exact date format in the text field (txtDDate). My problem is I need
some javascript that sets an alert that does not allow them to select
today.

example:
var dtToday = Date()
if(document.frmSoftware.txtDDate.value == dtToday)
{
alert("You cannot select same day distributions. Please enter a new
value in the \"Delivery Date\" field.");
return false
}

But dtToday is blank....How can I get dtToday value? Also, when I set
the dtToday value outside javascript and used a Response.Write to see
what format Date() came up with - it gave me 1/24/2005 - but the
calendar pop-up gives me 01/24/2005....could this also be the issue?
Thanks is advance!
Lisa
 
B

BMR

You should format dtToday with Date methods ie dtToday.toLocaleString()
or rather with getDate(), getMonth() and getFullYear(). Because when you
write dtToday, in fact it writes dtToday.toString(), which is "Mon Jan
24 17:06:17 2005" (my local time). dtToday is an object, not a variable.

BMR

(e-mail address removed) a écrit :
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Mon, 24 Jan 2005 05:27:01, seen in (e-mail address removed) posted :
I have an asp page that uses a calendar.js (pop-up) file to add an
exact date format in the text field (txtDDate). My problem is I need
some javascript that sets an alert that does not allow them to select
today.

example:
var dtToday = Date()

Should be new Date() ; or at least that usually would be used.
In my browser, Date() gives a string unequal to that given by using
new Date().toString() . Date() ignores its parameter.

Both of them give date-and-time.
if(document.frmSoftware.txtDDate.value == dtToday)

The left side is a string as entered by the user, who *may* have used
the format that you expect.
{
alert("You cannot select same day distributions. Please enter a new
value in the \"Delivery Date\" field.");

Code should be indented to show intended structure.
In News, code lines should NOT be broken by the sending agent;
transmitted code should be executable directly. Better for you to do it
right than to have all your readers trying to repair the damage.
return false
}

But dtToday is blank....How can I get dtToday value?

Perhaps your system interprets Date() differently.
Also, when I set
the dtToday value outside javascript and used a Response.Write to see
what format Date() came up with - it gave me 1/24/2005 - but the
calendar pop-up gives me 01/24/2005....could this also be the issue?

Even though those are FFF, that is not the main issue; merely a residual
future cause of failure.

ISTM that you are asking to ensure that the requested date is not today.
But why? Very probably you want it to be after today, so disallowing
today-or-before.

If you check that the requested date is a valid date, preferably as
YYYY-MM-DD but in FFF if you must, then you can read it into a Date
Object and it will mean 00:00:00 local of the date in question. If it
were any earlier than 00:00:00 tomorrow, it would be 00:00:00 today or
earlier, i.e. before the current moment. You can therefore compare
new Date().valueOf() < new Date(userdata).valueOf()
if you are confident that the user format (after validation) is read
correctly in whatever localisation your system has; or
new Date().valueOf() < new Date(Y, M, D).valueOf()
with Y M D (or +Y +M +D) being generated during validation.


To check that a date is equal to another date, you must remove the time
components. Those blessed enough to be using GMT can use
(new Date()/864e5)|0 == (new Date(Y, M, D)/864e5)|0
but others will need to extract Y M D from each and use either
Y1==Y2 && M1==M2 && D1==D2
or as
(Y1*100+M1)*100+D1 == (Y2*100+M2)*100+D2



Read the newsgroup FAQ; see below.
 
P

peashoe

John,
Thanks for the reply 'except for the indent comment' Not sure why you
would make that remark because you know google groups formats what you
paste to whatever it feels like.

In any case, I went another route and updated my calendar.js file to
not accept same day selection.

I will keep this chunk of info for future reference though
Thanks again

~L~
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Tue, 25 Jan 2005 10:50:53, seen in
peashoe said:
Thanks for the reply 'except for the indent comment' Not sure why you
would make that remark because you know google groups formats what you
paste to whatever it feels like.

You chose to use Google, when you could have chosen a proper newsreader
or a different, better-designed Web service. The responsibility is
yours; you do not yet live in a world-wide dictatorship forcing use of
Google.

Code should be indented to show the intended meaning; it is unreasonable
to expect others to fathom out the intended structure - which is not
necessarily the actual structure - of badly-presented material.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top