I am working on a problem and desperately need help!
I need to prompt a user for the numerical month of birth, day of birth and
year of birth and store it in varialbes and the use the variables to build a
date object. Then print the resulting date object, in it's full form. on
the screen using document.write. This IS for school and I think I am
starting out right, but can't quite seem to grasp what I am doing wrong, or
where to go from here. Any tips would be greatly appreciated.
Here is what I have so far...
<script>
var mob=prompt("Wha t is your month of birth, numerically?", "04");
var dob=prompt("Wha t is the date of your birth, numerically?", "07");
var yob=prompt("Wha t is the year of your birth, numerically?", "1967");
month.setMonth( mob-1);
day.setDate(dob );
year.setFullYea r(yob);
document.write( "Your birthday is " + date + "<br>");
</script>
KL 16 2093
KL said: I am working on a problem and desperately need help!
I need to prompt a user for the numerical month of birth, day of birth and year of birth and store it in varialbes and the use the variables to build a date object. Then print the resulting date object, in it's full form. on the screen using document.write. This IS for school and I think I am starting out right, but can't quite seem to grasp what I am doing wrong, or where to go from here. Any tips would be greatly appreciated.
Here is what I have so far...
<script> var mob=prompt("Wha t is your month of birth, numerically?", "04"); var dob=prompt("Wha t is the date of your birth, numerically?", "07"); var yob=prompt("Wha t is the year of your birth, numerically?", "1967"); month.setMonth (mob-1); day.setDate(do b); year.setFullYe ar(yob); document.write ("Your birthday is " + date + "<br>"); </script>
You want to have a single date object, not one each for month, day and year.
The easiest way to do that is to use the form of the Date() constructor that
takes month, day and year as arguments.
var date=new Date(...left for you to find...or ask about...);
document.write( ...as you have it...);
"Lee" <RE************ **@cox.net> wrote in message
news:co******** *@drn.newsguy.c om... KL said: I am working on a problem and desperately need help!
I need to prompt a user for the numerical month of birth, day of birth and year of birth and store it in varialbes and the use the variables to build a date object. Then print the resulting date object, in it's full form. on the screen using document.write. This IS for school and I think I am starting out right, but can't quite seem to grasp what I am doing wrong, or where to go from here. Any tips would be greatly appreciated.
Here is what I have so far...
<script> var mob=prompt("Wha t is your month of birth, numerically?", "04"); var dob=prompt("Wha t is the date of your birth, numerically?", "07"); var yob=prompt("Wha t is the year of your birth, numerically?", "1967"); month.setMont h(mob-1); day.setDate(d ob); year.setFullY ear(yob); document.writ e("Your birthday is " + date + "<br>"); </script>
You want to have a single date object, not one each for month, day and year. The easiest way to do that is to use the form of the Date() constructor that takes month, day and year as arguments.
var date=new Date(...left for you to find...or ask about...); document.write( ...as you have it...);
OK I have read and reread this and I think I get some of it. But I am
confused as to what a Date() Constructor is. I don't think we covered that
in class and I don't find it in my book...or I didn't look right..I will
look again, but in the meantime, what can someone tell me about the Date()
Constructor?
KL
KL wrote:
[...] OK I have read and reread this and I think I get some of it. But I am confused as to what a Date() Constructor is. I don't think we covered that in class and I don't find it in my book...or I didn't look right..I will look again, but in the meantime, what can someone tell me about the Date() Constructor?
Try the following:
<script type="text/javascript">
var mob=prompt("Wha t is your month of birth, numerically?"," 04");
var dob=prompt("Wha t is the date of your birth, numerically?"," 07");
var yob=prompt("Wha t is the year of your birth, numerically?"," 1967");
var bDay= new Date(yob,mob,do b);
alert(bDay);
</script>
--
Rob
"RobG" <rg***@iinet.ne t.auau> wrote in message
news:41******** *************** @per-qv1-newsreader-01.iinet.net.au ... KL wrote: [...] OK I have read and reread this and I think I get some of it. But I am confused as to what a Date() Constructor is. I don't think we covered that in class and I don't find it in my book...or I didn't look right..I will look again, but in the meantime, what can someone tell me about the Date() Constructor?
Try the following:
<script type="text/javascript"> var mob=prompt("Wha t is your month of birth, numerically?"," 04"); var dob=prompt("Wha t is the date of your birth, numerically?"," 07"); var yob=prompt("Wha t is the year of your birth, numerically?"," 1967");
var bDay= new Date(yob,mob,do b); alert(bDay); </script>
-- Rob
Thanks Rob...that helped immensely. I get what I was doing wrong. And best
of all it works now :)
KL
JRS: In article <41********@127 .0.0.1>, dated Sat, 27 Nov 2004
23:06:24, seen in news:comp.lang. javascript, KL <kl*******@aohe ll.com>
posted : "RobG" <rg***@iinet.ne t.auau> wrote in message news:41******* *************** *@per-qv1-newsreader-01.iinet.net.au ... KL wrote: [...] OK I have read and reread this and I think I get some of it. But I am confused as to what a Date() Constructor is. I don't think we covered that in class and I don't find it in my book...or I didn't look right..I will look again, but in the meantime, what can someone tell me about the Date() Constructor?
Try the following:
<script type="text/javascript"> var mob=prompt("Wha t is your month of birth, numerically?"," 04"); var dob=prompt("Wha t is the date of your birth, numerically?"," 07"); var yob=prompt("Wha t is the year of your birth, numerically?"," 1967");
var bDay= new Date(yob,mob,do b); alert(bDay); </script>
-- Rob
Thanks Rob...that helped immensely. I get what I was doing wrong. And best of all it works now :)
You saw Rob's omission, then?
Moreover, note that by reading back (two of) the fields from bDay, you
can verify the date as being good Gregorian. Be careful, though, with
historical dates; William Penn's son John "The American", the first by
his second wife, was born on 1700-02-29. See sig below.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Dr John Stockton wrote:
[..] Moreover, note that by reading back (two of) the fields from bDay, you can verify the date as being good Gregorian. Be careful, though, with historical dates; William Penn's son John "The American", the first by his second wife, was born on 1700-02-29. See sig below.
Yes, I forgot that. It is certainly an issue as different browsers
support different ranges.
I think the consensus was that since getFullYear() is not always
available, checking that the created date object's date and month were
equal to the input date and month was simplest (provided the OP
remembers to add one to the month...).
--
Rob
"RobG" <rg***@iinet.ne t.auau> wrote in message
news:04******** *********@news. optus.net.au... Dr John Stockton wrote: [..] Moreover, note that by reading back (two of) the fields from bDay, you can verify the date as being good Gregorian. Be careful, though, with historical dates; William Penn's son John "The American", the first by his second wife, was born on 1700-02-29. See sig below.
Yes, I forgot that. It is certainly an issue as different browsers support different ranges.
I think the consensus was that since getFullYear() is not always available, checking that the created date object's date and month were equal to the input date and month was simplest (provided the OP remembers to add one to the month...).
I remembered about the date offset of 1, but I am lost as to the other
issue. Can you really dumb it down for me?
KL
-- Rob
KL wrote: "RobG" <rg***@iinet.ne t.auau> wrote in message news:04******** *********@news. optus.net.au...
[...] Yes, I forgot that. It is certainly an issue as different browsers support different ranges.
I think the consensus was that since getFullYear() is not always available, checking that the created date object's date and month were equal to the input date and month was simplest (provided the OP remembers to add one to the month...).
I remembered about the date offset of 1, but I am lost as to the other issue. Can you really dumb it down for me?
When you create a date object using year, month and day you may be
trying to create a date outside the range that the browser can handle.
Since you don't know what browser a user may be using, the easiest way
is to test the date you create against the input you created it from
(assuming you've validated that the input was OK in the first place,
that is that the year is a number, month is between 1 and 12 inclusive
and the day date between 1 and 31 inclusive).
Consider the following function:
function makeDate(y,m,d) {
var theDate = new Date(y,m-1,d);
return theDate;
}
Provided we call it with something like:
alert('The date is ' + makeDate('2003' ,'0','5'));
we should get an alert telling us the date is 5 January, 2003. In some
browsers, (e.g. Safari) if we use:
alert('The date is ' + makeDate('1803' ,'0','5'));
we'll get an error because it can't handle that dates before 1900 or
after 2038 (most other browsers can). So the best way to test is,
after creating our date, to use:
if(theDate.getM onth() != m || theDate.getDate () != d) {
alert('Can't handle date ' + y +'-' + m + '-' + d);
return false;
} else {
return theDate;
}
If you want to be really sure, add: || theDate.getFull Year() != y
However, getFullYear() may not be implemented and rather than messing
around with testing if it is or not, then seeing if the year is less
than 1900 then adding 1900, just don't test the year. The chance that
the month and date will be OK but year incorrect is pretty slim (in
this particular case).
Having said that, if you are going to use getFullYear(), you must test
that the browser supports it first and if not, use some alternative
(say use getYear() and if it returns a value less than 1900, add 1900).
For more fun, follow the link in Dr J's signature:
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates,
sources.
--
Rob
"RobG" <rg***@iinet.ne t.auau> wrote in message
news:gV******** *********@news. optus.net.au... KL wrote: "RobG" <rg***@iinet.ne t.auau> wrote in message news:04******** *********@news. optus.net.au... [...] Yes, I forgot that. It is certainly an issue as different browsers support different ranges.
I think the consensus was that since getFullYear() is not always available, checking that the created date object's date and month were equal to the input date and month was simplest (provided the OP remembers to add one to the month...).
I remembered about the date offset of 1, but I am lost as to the other issue. Can you really dumb it down for me?
When you create a date object using year, month and day you may be trying to create a date outside the range that the browser can handle. Since you don't know what browser a user may be using, the easiest way is to test the date you create against the input you created it from (assuming you've validated that the input was OK in the first place, that is that the year is a number, month is between 1 and 12 inclusive and the day date between 1 and 31 inclusive).
Consider the following function:
function makeDate(y,m,d) { var theDate = new Date(y,m-1,d); return theDate; }
Provided we call it with something like:
alert('The date is ' + makeDate('2003' ,'0','5'));
we should get an alert telling us the date is 5 January, 2003. In some browsers, (e.g. Safari) if we use:
alert('The date is ' + makeDate('1803' ,'0','5'));
we'll get an error because it can't handle that dates before 1900 or after 2038 (most other browsers can). So the best way to test is, after creating our date, to use:
if(theDate.getM onth() != m || theDate.getDate () != d) { alert('Can't handle date ' + y +'-' + m + '-' + d); return false; } else { return theDate; }
If you want to be really sure, add: || theDate.getFull Year() != y
However, getFullYear() may not be implemented and rather than messing around with testing if it is or not, then seeing if the year is less than 1900 then adding 1900, just don't test the year. The chance that the month and date will be OK but year incorrect is pretty slim (in this particular case).
Having said that, if you are going to use getFullYear(), you must test that the browser supports it first and if not, use some alternative (say use getYear() and if it returns a value less than 1900, add 1900).
For more fun, follow the link in Dr J's signature:
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
-- Rob
Thanks for that! I am learning so much!!
KL This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: mirza i |
last post by:
thanks for the previous replies.
here is the new question (i'm absolutely sure that this should be VERY easy
for a good js coder)
ok:
from asp i call:
<img src="pics/cal.gif"
onclick="show_calendar_det('document.invdetdet.dx1',
|
by: Steve Elliott |
last post by:
I have a query set up to gather together data between two specified dates.
Shown in the query column as:
Between #24/09/2004# And #01/10/2004#
Is it possible to enter several different date ranges, ie between 24/09/2004
and 01/10/2004 together with 05/10/2004 and 07/10/2004 ?
If I enter the "Between" criteria on different lines it returns no data.
|
by: Kermit Piper |
last post by:
Hello,
I am comparing two date values, one from a database and one that has
been converted from a hard-coded string into an actual Date type. So
far so good. The problem I'm having is that one of the values comes
from the database, and for existing values it works fine, but if the
date doesn't exist (which will always be the condition when the user
first enters into the form) I am adding logic to my javascript like: if
(dbDate <...
|
by: Luvin lunch |
last post by:
Hi,
I'm new to access and am very wary of dates as I have limited
experience in their manipulation and I know if they're not done
properly things can turn ugly quickly.
I would like to use a calendar control to allow my users to enter a
date but I need them to enter a time as well. It doesn't look like the
calendar control will allow times to be entered so I was thinking of
having two text boxes. One text box would contain the date...
|
by: syntego |
last post by:
We commonly use triggers to log changes to our main tables to
historical log tables.
In the trigger, we create a concatenated string of the old values by
casting them as follows:
CAST(O.MYDATE AS CHAR(30))
When directly updating date fields in the main table, the logged value
gets saved in the format YYYY-MM-DD as expected.
| |
by: user |
last post by:
Hi,
Let's say I have 2 dates in the b/m format:
Date 1 and date 2
How do I check whether Date2 is later than Date 1?
Date1. 21-Nov-2006 09:00:00 PM
|
by: dan |
last post by:
Am i breaking any rules when I loop dates like
// Determine Memorial Day
intFlag = 0;
memDayHol = new Date (currentYear, 4, 31);
while (intFlag == 0) {
if (memDayHol.getDay() == 1) {intFlag =1;}
else {memDayHol = memDayHol - 1;}
}
|
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 date format in the table design, such as: mm/dd/yyyy?
What I've done for years is to store the date format in date fields, then on
the forms, based on their region, I would set the date formats on form_load
|
by: Martin |
last post by:
I'm retrieving some records from a database. One of the fields
contains a date/time. I would like to format it as I send it out to
the table in the displayed page.
Can some one please tell me how I can/should do that? Or possibly
point me to an on-line explanation?
Thanks
ps: if it makes any difference, the data is coming from a MS Access
|
by: Geoff Cox |
last post by:
Hello,
at the moment I can add the combined date and time into MySQL using
php
$dt1 = date("Y-m-d H:i:s");
is it possible to add the date and time separately?
I thought it might be
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |