By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,678 Members | 1,287 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,678 IT Pros & Developers. It's quick & easy.

Date and time

P: n/a
Say I put a date and time for like this:
Jun-15-04 21:52:06

Here is the form I am using:
<form>
<p><input type="text" name="T1" size="20"><br>
date</p>
<p><input type="text" name="T2" size="20"><br>
90 days from date</p>
<p><input type="submit" value="Submit" name="B1"></p>
</form>

How could I get to show the date 90 days later to the exact date and time.
I would enter the data in the first box and hit submit to show in the second
box.

TIA
Jul 23 '05 #1
Share this Question
Share on Google+
21 Replies


P: n/a
Lee
Samir said:

Say I put a date and time for like this:
Jun-15-04 21:52:06

Here is the form I am using:
<form>
<p><input type="text" name="T1" size="20"><br>
date</p>
<p><input type="text" name="T2" size="20"><br>
90 days from date</p>
<p><input type="submit" value="Submit" name="B1"></p>
</form>

How could I get to show the date 90 days later to the exact date and time.
I would enter the data in the first box and hit submit to show in the second
box.


If you're not going to be sending the data to your server,
you shouldn't use a submit element. Use an input of type
"button", instead.

<input type="button"
value="Submit"
onclick="this.form.date2.value=plus90(this.form.da te1.value)">

"T1" and "T2" (and "B1") are pretty bad names for form fields.
Why not at least "date1" and "date2"?

As for what the function I've called plus90() should do,
check the date manipulation links referenced in the FAQ:
http://www.jibbering.com/faq/

You may want to rethink the input format.
It's a lot easier if the format is "Jun 15 2004 21:52:06".

Jul 23 '05 #2

P: n/a
Lee wrote on 19 aug 2004 in comp.lang.javascript:
Samir said:

Say I put a date and time for like this:
Jun-15-04 21:52:06
You may want to rethink the input format.
It's a lot easier if the format is "Jun 15 2004 21:52:06".


A lot??

t = "Jun-15-04 21:52:06"

t = t.replace(/-(\d\d) /," 20$1 ").replace(/-/g," ")

[allows also last century as 19..]

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #3

P: n/a
Lee <RE**************@cox.net> wrote:

Your From address does not specify a mailbox which is a violation of
Internet/Usenet standards and disregarding the Netiquette as well
as most certainly a violation of the Acceptable Use Policy of your
service provider.**You*have*been*warned.

<http://www.interhack.net/pubs/munging-harmful/>
Samir said:
Say I put a date and time for like this:
Jun-15-04 21:52:06

Here is the form I am using:
<form>
<p><input type="text" name="T1" size="20"><br>
date</p>
<p><input type="text" name="T2" size="20"><br>
90 days from date</p>
<p><input type="submit" value="Submit" name="B1"></p>
</form>

How could I get to show the date 90 days later to the exact date and
time. I would enter the data in the first box and hit submit to show in
the second box.
If you're not going to be sending the data to your server,
you shouldn't use a submit element. Use an input of type
"button", instead.


Wrong. Using a submit button may also be useful without a server, if it
is used in an application using only client-side scripting and the required
DOM access methods are for some reason not available or viable. Example:

<http://pointedears.de/scripts/test/ObjectInspector/nightly/latest/index>

It would be more correct to say that using a submit button is not viable
if re-accessing or changing the container element's resource is undesired
which is the case here.
You may want to rethink the input format.
It's a lot easier if the format is "Jun 15 2004 21:52:06".


Why?
PointedEars
--
Everyone thinks I'm psychotic, except for my friends deep inside the earth.
Jul 23 '05 #4

P: n/a
Lee
Evertjan. said:

Lee wrote on 19 aug 2004 in comp.lang.javascript:
Samir said:

Say I put a date and time for like this:
Jun-15-04 21:52:06

You may want to rethink the input format.
It's a lot easier if the format is "Jun 15 2004 21:52:06".


A lot??


Yes: var firstDate=new Date("Jun 15 2004 21:52:06");

Jul 23 '05 #5

P: n/a
JRS: In article <cg*********@drn.newsguy.com>, dated Wed, 18 Aug 2004
20:20:20, seen in news:comp.lang.javascript, Lee
<RE**************@cox.net> posted :
Samir said:

Say I put a date and time for like this:
Jun-15-04 21:52:06 How could I get to show the date 90 days later to the exact date and time.
As for what the function I've called plus90() should do,
check the date manipulation links referenced in the FAQ:
http://www.jibbering.com/faq/

You may want to rethink the input format.
It's a lot easier if the format is "Jun 15 2004 21:52:06".


Samir is probably a foreigner (everybody is probably a foreigner on the
Internet). Can one be sure that in all browsers the form "Jun" is
recognised? AFAICS, ECMA is indecisive in such matters (ICBW); and not
all software is compliant with applicable standards - some foreign
software systems are configured with excessive localisation.

Accordingly, I would suggest instead 2004/06/15 21:52:06 xxx
where xxx is either absent, a well-known time zone indicator, or an
offset from GMT. The form is as close to ISO 8601 as my browser will
accept.

Unless users are restricted to odd places like China, Hawaii, Guam, the
ISS, Iceland, Morocco, and Ghana, etc., the OP needs to decide whether
the 90 days are to be of real time or of user's civil time.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 23 '05 #6

P: n/a
Okay here is my redited code

<form>
<p><input type="text" name="date1" size="20"><br>
date</p>
<p><input type="text" name="date2" size="20"><br>
90 days from date</p>
<p><input type="button" value="Submit" name="B1"
onclick="this.form.date2.value=plus90(this.form.da te1.value)"></p>
</form>

I can't seem to know how to do this, I couldn't find the function in the
page you have said. Can anyone else help me?
<script language="javascript">
function plus90(){
???????????????????????????????????
}
</script>

"Lee" <RE**************@cox.net> wrote in message
news:cg*********@drn.newsguy.com...
Samir said:

Say I put a date and time for like this:
Jun-15-04 21:52:06

Here is the form I am using:
<form>
<p><input type="text" name="T1" size="20"><br>
date</p>
<p><input type="text" name="T2" size="20"><br>
90 days from date</p>
<p><input type="submit" value="Submit" name="B1"></p>
</form>

How could I get to show the date 90 days later to the exact date and time.I would enter the data in the first box and hit submit to show in the secondbox.


If you're not going to be sending the data to your server,
you shouldn't use a submit element. Use an input of type
"button", instead.

<input type="button"
value="Submit"
onclick="this.form.date2.value=plus90(this.form.da te1.value)">

"T1" and "T2" (and "B1") are pretty bad names for form fields.
Why not at least "date1" and "date2"?

As for what the function I've called plus90() should do,
check the date manipulation links referenced in the FAQ:
http://www.jibbering.com/faq/

You may want to rethink the input format.
It's a lot easier if the format is "Jun 15 2004 21:52:06".


Jul 23 '05 #7

P: n/a
Samir wrote on 19 aug 2004 in comp.lang.javascript:
Okay here is my redited code

<form>
<p><input type="text" name="date1" size="20"><br>
date</p>
<p><input type="text" name="date2" size="20"><br>
90 days from date</p>
<p><input type="button" value="Submit" name="B1"
onclick="this.form.date2.value=plus90(this.form.da te1.value)"></p>
</form>

I can't seem to know how to do this, I couldn't find the function in
the page you have said. Can anyone else help me?


<form>
<input type="text" name="date1" size="20"><br>
date (yyyy/mm/dd)<br><br>
<input type="text" name="date2" size="20" readonly><br>
90 days from date<br><br>
<input type="button" value="Calculate"
onclick="plus90(this);">
</form>
<script type="text/javascript">

document.forms(0).date1.value = dateToString(new Date())

function dateToString(d){
return [d.getYear(),d.getMonth()+1,d.getDate()].join('/')
}

function plus90(x){
d = new Date(x.form.date1.value)
d = new Date(d.getYear(),d.getMonth(),d.getDate()+90)
x.form.date2.value = dateToString(d)
}

</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #8

P: n/a
On 19 Aug 2004 19:39:10 GMT, Evertjan. <ex**************@interxnl.net>
wrote:

[snip]
function dateToString(d){
return [d.getYear(),d.getMonth()+1,d.getDate()].join('/')
}

function plus90(x){
d = new Date(x.form.date1.value)
d = new Date(d.getYear(),d.getMonth(),d.getDate()+90)


Wouldn't

d = new Date(...);
d.setDate(d.getDate() + 90);

be simpler?

Also, getFullYear() is preferable to getYear().

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #9

P: n/a
Michael Winter wrote on 19 aug 2004 in comp.lang.javascript:
Wouldn't

d = new Date(...);
d.setDate(d.getDate() + 90);

be simpler?
Yes, more concise, but perhaps not as clear to the OP.

Also, getFullYear() is preferable to getYear().


Why, in this case?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #10

P: n/a
Thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn********************@194.109.133.29...
Samir wrote on 19 aug 2004 in comp.lang.javascript:
Okay here is my redited code

<form>
<p><input type="text" name="date1" size="20"><br>
date</p>
<p><input type="text" name="date2" size="20"><br>
90 days from date</p>
<p><input type="button" value="Submit" name="B1"
onclick="this.form.date2.value=plus90(this.form.da te1.value)"></p>
</form>

I can't seem to know how to do this, I couldn't find the function in
the page you have said. Can anyone else help me?


<form>
<input type="text" name="date1" size="20"><br>
date (yyyy/mm/dd)<br><br>
<input type="text" name="date2" size="20" readonly><br>
90 days from date<br><br>
<input type="button" value="Calculate"
onclick="plus90(this);">
</form>
<script type="text/javascript">

document.forms(0).date1.value = dateToString(new Date())

function dateToString(d){
return [d.getYear(),d.getMonth()+1,d.getDate()].join('/')
}

function plus90(x){
d = new Date(x.form.date1.value)
d = new Date(d.getYear(),d.getMonth(),d.getDate()+90)
x.form.date2.value = dateToString(d)
}

</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Jul 23 '05 #11

P: n/a
On 19 Aug 2004 19:58:27 GMT, Evertjan. <ex**************@interxnl.net>
wrote:
Michael Winter wrote on 19 aug 2004 in comp.lang.javascript:
Wouldn't

d = new Date(...);
d.setDate(d.getDate() + 90);

be simpler?


Yes, more concise, but perhaps not as clear to the OP.


I suppose. However I'm sure the OP would see "<something> + 90" as
increasing the days as originally requested.
Also, getFullYear() is preferable to getYear().


Why, in this case?


03/04/05

For the usual reason: what does that date represent?

That and the OP specifies the format on the page as yyyy/mm/dd. I think it
would be a good idea to stick with that.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #12

P: n/a
Michael Winter wrote on 19 aug 2004 in comp.lang.javascript:
03/04/05

For the usual reason: what does that date represent?
You are right, Michael.
I did not test for pre 1900-1999 years.
That and the OP specifies the format on the page as yyyy/mm/dd. I
think it would be a good idea to stick with that.


You are wrong,
he did not specify yyyy/mm/dd,
I did.
;-}

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #13

P: n/a
How would the function work if I were to test for pre 1900-1999 years????
"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn*******************@194.109.133.29...
Michael Winter wrote on 19 aug 2004 in comp.lang.javascript:
03/04/05

For the usual reason: what does that date represent?


You are right, Michael.
I did not test for pre 1900-1999 years.
That and the OP specifies the format on the page as yyyy/mm/dd. I
think it would be a good idea to stick with that.


You are wrong,
he did not specify yyyy/mm/dd,
I did.
;-}

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Jul 23 '05 #14

P: n/a
On 19 Aug 2004 21:45:01 GMT, Evertjan. <ex**************@interxnl.net>
wrote:

[snip]
You are right, Michael.
Mike will do just fine. :)

[snip]
You are wrong,
he did not specify yyyy/mm/dd,
I did.
;-}


Ermm. Yes, I knew that. (D'oh!)

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #15

P: n/a
Samir wrote on 19 aug 2004 in comp.lang.javascript:
How would the function work if I were to test for pre 1900-1999 years????


Slip of the keyboard:

My sentence was first .. pre 2000 .. , than I changed it to 1900-1999 and
left the pre in ;-)

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #16

P: n/a
Thomas 'PointedEars' Lahn wrote:
Lee <RE**************@cox.net> wrote:

Your From address does not specify a mailbox which is a violation of
Internet/Usenet standards and disregarding the Netiquette as well
as most certainly a violation of the Acceptable Use Policy of your
service provider. You have been warned.
Will you please explain the difference between a "munged" address and an
"un-mailable" address? Since you seem to have a problem with munging,
and you want to "warn" everyone, please explain. And since you can *not*
send email to the From: address in my post, you will have to answer it here.
<http://www.interhack.net/pubs/munging-harmful/>


Reads like it was written by a spam-harvesting-programmer. Utter Junk to
anyone with half a sense of intelligence.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #17

P: n/a
MA

"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:opsczv7706x13kvk@atlantis...
On 19 Aug 2004 19:39:10 GMT, Evertjan. <ex**************@interxnl.net>
wrote:

[snip]
function dateToString(d){
return [d.getYear(),d.getMonth()+1,d.getDate()].join('/')
}

function plus90(x){
d = new Date(x.form.date1.value)
d = new Date(d.getYear(),d.getMonth(),d.getDate()+90)


Wouldn't

d = new Date(...);
d.setDate(d.getDate() + 90);

be simpler?

Also, getFullYear() is preferable to getYear().

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.

Hi!

I used your code like this:
<!--
function onclickHandler(oGridCell, date)
{
var objDate = new Date();
//split date in year, month, day
dateSplitter = date.split("-");
//set date for date object.
objDate.setFullYear(dateSplitter[0], dateSplitter[1], dateSplitter[2]);
//date argument only contains the first date of the week since I get the
value from the first cell in my table.
//Thats the cause of cellIndex. -4 is because there is four columns
before the actual date.
returnDate = objDate.getFullYear()+objDate.getMonth()+objDate.g etDay();
alert(oGridCell.cellIndex-4);
alert(dateToString(objDate, (oGridCell.cellIndex-4)));
}

function dateToString(d, addDays)
{
d.setDate(d.getDate()+addDays);
return [d.getYear(),d.getMonth(),d.getDate()].join('/');
}

-->
It really works fine if I dont add a value that results in a new month.
When I used todays date (20040820) and the value of addDays where 11, I got
the value 2004/09/01. This should be 2004/08/31. Dos any of you know whats
wrong with this?

/Marre
Jul 23 '05 #18

P: n/a
On Fri, 20 Aug 2004 15:48:38 +0200, MA <ne**@supremelink.se> wrote:
function dateToString(d, addDays)
{
d.setDate(d.getDate()+addDays);
return [d.getYear(),d.getMonth(),d.getDate()].join('/');
}

It really works fine if I dont add a value that results in a new month.
When I used todays date (20040820) and the value of addDays where 11, I
got the value 2004/09/01. This should be 2004/08/31. Dos any of you
know whats wrong with this?


The getMonth() method returns a value between zero (0) and eleven (11),
not one (1) and twelve (12). Add one to the returned value and you be part
of the way there.

Similarly, the setFullYear() method expects the months to be numbered from
one to eleven. When you pass eight (8), instead of specifying August,
you're actually setting September (which only has 30 days, hence the
rollover). You'll want to subtract one from the value you use.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #19

P: n/a
MA

"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:opsc1aq1vjx13kvk@atlantis...
On Fri, 20 Aug 2004 15:48:38 +0200, MA <ne**@supremelink.se> wrote:
function dateToString(d, addDays)
{
d.setDate(d.getDate()+addDays);
return [d.getYear(),d.getMonth(),d.getDate()].join('/');
}

It really works fine if I dont add a value that results in a new month.
When I used todays date (20040820) and the value of addDays where 11, I
got the value 2004/09/01. This should be 2004/08/31. Dos any of you
know whats wrong with this?


The getMonth() method returns a value between zero (0) and eleven (11),
not one (1) and twelve (12). Add one to the returned value and you be part
of the way there.

Similarly, the setFullYear() method expects the months to be numbered from
one to eleven. When you pass eight (8), instead of specifying August,
you're actually setting September (which only has 30 days, hence the
rollover). You'll want to subtract one from the value you use.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.

Aha!
Should have thougt of that :)

Thanx!!

/Marre
Jul 23 '05 #20

P: n/a
JRS: In article <Xn********************@194.109.133.29>, dated Thu, 19
Aug 2004 19:58:27, seen in news:comp.lang.javascript, Evertjan.
<ex**************@interxnl.net> posted :
Michael Winter wrote on 19 aug 2004 in comp.lang.javascript:
Wouldn't

d = new Date(...);
d.setDate(d.getDate() + 90);

be simpler?


Yes, more concise, but perhaps not as clear to the OP.


It preserves the civil time (if possible) which was a requirement stated
in the original posting. It uses only one Date Object, which seems
nicer.
Also, getFullYear() is preferable to getYear().


Why, in this case?


Showing a four-digit year, if permissible, should always be preferred.
Likewise following ISO 8601, at least in spirit.

Note that getYear (according to information received, can only be relied
on to give a result of 0..99 for years 1900-99. To get a two-digit year
as a number, one needs to use %100. To get a two-digit string, %100 &
LZ, or add a sufficient multiple of 100, convert to string, and use the
last two characters. There may be other ways.
If getFullYear may be unavailable : I have code for determining the Full
Year Number using getYear and either valueOf or getTime; the only
assumption AFAICS is that getYear is correct modulo 100.

--
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 #21

P: n/a
In article <PV*******************@fe08.usenetserver.com>, Samir
<Sa***@hotmail.com> wrote:
Okay here is my redited code

<form>
<p><input type="text" name="date1" size="20"><br>
date</p>
<p><input type="text" name="date2" size="20"><br>
90 days from date</p>
<p><input type="button" value="Submit" name="B1"
onclick="this.form.date2.value=plus90(this.form.da te1.value)"></p>
</form>

I can't seem to know how to do this, I couldn't find the function in the
page you have said. Can anyone else help me?
<script language="javascript">
function plus90(){

<snip>

You did not read the response correctly. It stated that you would have
to write a function called "plus90" (or anything else). It is up to you
to look up how to use date functions and decide how to add 90 days.
This forum can not teach you everything you need to know about dates
and functions.

There is a date calculator at my site that can manipulate dates. You
may get some ideas there. I would not recommend a single date input
field. You should have separate fields for month, day, and year in
order to validate them. Why include the time when it does not change?

--
Dennis Marks
http://www.dcs-chico.com/~denmarks/
Mail to the return email address is bounced.
Go to web site for active email address.
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 23 '05 #22

This discussion thread is closed

Replies have been disabled for this discussion.