473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

get/format date field

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

Jul 23 '05 #1
4 3417
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

pe*****@yahoo.com a écrit :
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

Jul 23 '05 #2
JRS: In article <11********************@z14g2000cwz.googlegroups.c om>,
dated Mon, 24 Jan 2005 05:27:01, seen in news:comp.lang.javascript,
pe*****@yahoo.com 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.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #3
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~

Jul 23 '05 #4
JRS: In article <11**********************@f14g2000cwb.googlegroups .com>
, dated Tue, 25 Jan 2005 10:50:53, seen in news:comp.lang.javascript,
peashoe <pe*****@yahoo.com> posted :
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.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Colin Steadman | last post by:
I'm a stupid ASP programmer and I dont do Javascript (except for very simple tasks anyway), and I'm in a bit of a predicament. I've used a javascript table sorting script from here: ...
5
by: Macca | last post by:
Hi, I have a table which has a date/time field. I am storing them as follows :- 01/01/2005 11:25 01/01/2005 19:44 02/01/2005 05:04
9
by: David Rysdam | last post by:
I have a large amount of data that I copy in and out of Sybase very often. Now I also want to copy this data in and out of postgres. I have an existing script that creates the entire database(s)...
1
by: G Gerard | last post by:
Hello I am having some problem comparing dates with the SQL statement below MySQL = "SELECT Format(Date, 'yyyy/mmmm/dd') as FROM TblDates WHERE _ Format(Date, 'yyyy/mmmm/dd') =...
1
by: scott | last post by:
Hi Everyone, I don't know if this is the correct forum but I thought i'd ask. I have an access DB with a function to automatically safe a table with fields i'm mail merging into MS Word. Word...
2
by: Billy | last post by:
This string is supposed to provide all records from an MDB database that match the courier and date specified in the query. I Response.Write the query and I get a date as 1/27/2007. The date...
10
by: ARC | last post by:
Hello all, General question for back-end database that has numerous date fields where the database will be used in regions that put the month first, and regions that do not. Should I save a...
3
by: veaux | last post by:
The date format mmddyyyy is common but I realize it's not a standard format in Access. There must be a simple way to provide this format to Access so it treats it as a date? In past, I play with...
3
by: Bface | last post by:
Hi all, Hope everyone had a good holiday. I am having a difficult time changing the date format of a field from Excel. I have never had this problem before. I link the excel spreadsheet to my DB,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.