473,779 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

adding to a ddmmyyyy date

Hi All.

I'm having a problem adding days to a date.

My date is in the string format dd/mm/yyyy eg. 23/08/2007 in my
form field.

I can't work out how to add 50 days to that date and then write it to
another form field.

Any help would be appreciated.

Aug 8 '07 #1
17 3449
On Aug 8, 3:16 am, ginajohnst <ginajoh...@gma il.comwrote:
Hi All.

I'm having a problem adding days to a date.

My date is in the string format dd/mm/yyyy eg. 23/08/2007 in my
form field.

I can't work out how to add 50 days to that date and then write it to
another form field.

Any help would be appreciated.
Which part can't you figure out? See the FAQ for date manipulation.
To change a form element's value, set its value property.

Aug 8 '07 #2
In comp.lang.javas cript message <46************ **@PointedEars. de>, Wed,
8 Aug 2007 10:42:09, Thomas 'PointedEars' Lahn <Po*********@we b.de>
posted:
>Quickhack:
but not well tested. It gives
23/02/2007 + 50 -12/04/2007
23/08/2007 + 50 -12/10/2007

But February is shorter than August, and should give days 3 more.
var
a = formField.value .split("/"),
d = new Date(
parseInt(a[2], 10), parseInt(a[1], 10), parseInt(a[0], 10) + 50);
d = new Date(a[2], a[1]-1, a[0]+50) // suffices

One can replace, in this context, parseInt by unary +; and that will in
context be effectively implicit.
anotherFormFiel d.value =
String(d.getDat e() * 1e6 + d.getMonth() * 1e4 + d.getFullYear() )
.replace(/(\d\d)(\d\d)(\d {4})/, "$1/$2/$3");
Do you find that better than, with suitable LZ,

anotherFormFiel d.value =
LZ(d.getDate()) + '/' + LZ(d.getMonth() +1) + '/' + d.getFullYear()

// ??

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v6.05 IE 6
news:comp.lang. javascript FAQ <URL:http://www.jibbering.c om/faq/index.html>.
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Aug 8 '07 #3
In comp.lang.javas cript message <f9*********@dr n.newsguy.com>, Wed, 8
Aug 2007 05:48:47, Lee <RE************ **@cox.netposte d:
>My date is in the string format dd/mm/yyyy eg. 23/08/2007 in my
>Once you understand it completely, you should be able to come up
with a much simpler solution that actually works.

http://docs.sun.com/source/816-6408-10/date.htm
/* There must be a nicer-looking version of that page, with a margin */
/* Note its error in a line starting like <tt>millisecond s</tt*/
/* They seem to ignore that UT != UTC */

Which parts of that page d0 you believe to deal with the reading and
writing of non-FFF numeric date strings??

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demo n.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Aug 8 '07 #4
Dr J R Stockton wrote:
[...] Thomas 'PointedEars' Lahn [...] posted:
>Quickhack:

but not well tested.
Hence *quick**hack*.
It gives
23/02/2007 + 50 -12/04/2007
23/08/2007 + 50 -12/10/2007

But February is shorter than August, and should give days 3 more.
Confirmed in FF 2.0.0.6 :-/ But where is the error here? If it isn't mine,
can someone quickly point out anything in ES3 that specifies it?
> var
a = formField.value .split("/"),
d = new Date(
parseInt(a[2], 10), parseInt(a[1], 10), parseInt(a[0], 10) + 50);

d = new Date(a[2], a[1]-1, a[0]+50) // suffices
Would that not have the same February problem as my solution?
One can replace, in this context, parseInt by unary +; and that will in
context be effectively implicit.
I had thought about that, but what about octals?
> anotherFormFiel d.value =
String(d.getDat e() * 1e6 + d.getMonth() * 1e4 + d.getFullYear() )
.replace(/(\d\d)(\d\d)(\d {4})/, "$1/$2/$3");

Do you find that better than, with suitable LZ,

anotherFormFiel d.value =
LZ(d.getDate()) + '/' + LZ(d.getMonth() +1) + '/' + d.getFullYear()

// ??
Hm. No. I just liked your previous solution and had my quickhack based on it.
PointedEars
--
"Use any version of Microsoft Frontpage to create your site. (This won't
prevent people from viewing your source, but no one will want to steal it.)"
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Aug 8 '07 #5
Thomas 'PointedEars' Lahn said the following on 8/8/2007 6:18 PM:
ginajohnst wrote:
>On Aug 8, 9:48 pm, Lee <REM0VElbspamt. ..@cox.netwrote :
>>ginajohnst said:
Once you understand it completely, you should be able to come up
with a much simpler solution that actually works.

My solution works alright.
Is that why you agreed with John when he pointed out a flaw in it?
If one had tested it, as I did, one would have known.
Obviously you didn't or you wouldn't have agreed with John in his
assessment of it having flaws in it.
But what to expect from a noname person with headers disregarding
Internet standards, Netiquette and their ISP's terms of service?
Whatever you were smoking, snorting or swallowing when you wrote that
garbage you should endeavor to stay away from.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 8 '07 #6
Lee
Thomas 'PointedEars' Lahn said:
>
ginajohnst wrote:
>On Aug 8, 9:48 pm, Lee <REM0VElbspamt. ..@cox.netwrote :
>>ginajohnst said:
>>Once you understand it completely, you should be able to come up
with a much simpler solution that actually works.

My solution works alright. If one had tested it, as I did, one would have
known. But what to expect from a noname person with headers disregarding
Internet standards, Netiquette and their ISP's terms of service?
You think you tested that?

Can you explain how it can work properly when you don't subtract
one from the month before passing it to the Date constructor?

Can you explain how your ludicrous multiplication method works
if the resulting date is earlier than the 10th of the month?

Try these inputs, genius:
01/11/2008
13/11/2008
--

Aug 8 '07 #7
In comp.lang.javas cript message <Xn************ ********@194.10 9.133.242>
, Wed, 8 Aug 2007 21:32:37, Evertjan. <ex************ **@interxnl.net >
posted:
>
>d = new Date(d.getTime( ) + 50*24*60*60*100 0);

safer:
d.setTime(d.ge tTime() + 50*24*60*60*100 0);
Better, yes; but why safer?
>or, also easier:
d.setDate(d.ge tDate() + 50);
That's also safer. Starting at Saturday 2007-03-24 23:30, the first
gives us a Monday and the second a Sunday. 50 days are 7 weeks plus ONE
day.

Re another article : parseInt(S) for S being "08" or "09" gives zero
(the standard reluctantly allows that); so, in this context, if parseInt
is used then it does need ', 10'.

But without parseInt, "08" and "09" are taken as eight and nine;
although "077" is sixty-three, "078" is seventy-eight - at least,
wherever I've tried it. That seems compatible with ISO/IEC 16262 B.1.

Javascript lacks specific syntax for creating a Date Object of a given
Ordinal Date; it does not need any, since new Date(YYYY, 0, DDD)
suffices. For DDD, parseInt(DDD, 10) seems essential.

new Date(2007, 0, 077) // Mar 4
new Date(2007, 0, 078) // Mar 19

Similar considerations apply to YYYY - parseInt is necessary unless most
years before 800 will definitely not be used.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demo n.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Aug 9 '07 #8
Dr J R Stockton wrote on 09 aug 2007 in comp.lang.javas cript:
In comp.lang.javas cript message <Xn************ ********@194.10 9.133.242>
, Wed, 8 Aug 2007 21:32:37, Evertjan. <ex************ **@interxnl.net >
posted:
>>
>>d = new Date(d.getTime( ) + 50*24*60*60*100 0);

safer:
d.setTime(d.g etTime() + 50*24*60*60*100 0);

Better, yes; but why safer?
Because this

d = new Date((a[2]), (a[1])-1, (a[0]));
d = new Date(d.getTime( ) + 50*24*60*60*100 0);

is less understandable, so is bound to have more mistakes made.
>>or, also easier:
d.setDate(d.g etDate() + 50);
Pentakosta [Gr., 50] gives a perfect Pesach to Shavuot+1 arythmatic.
That's also safer. Starting at Saturday 2007-03-24 23:30, the first
gives us a Monday and the second a Sunday. 50 days are 7 weeks plus ONE
day.
Yes, indeed!
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 9 '07 #9
Lee
Dr J R Stockton said:
>
In comp.lang.javas cript message <f9*********@dr n.newsguy.com>, Wed, 8
Aug 2007 05:48:47, Lee <RE************ **@cox.netposte d:
>>My date is in the string format dd/mm/yyyy eg. 23/08/2007 in my
>>Once you understand it completely, you should be able to come up
with a much simpler solution that actually works.

http://docs.sun.com/source/816-6408-10/date.htm

/* There must be a nicer-looking version of that page, with a margin */
/* Note its error in a line starting like <tt>millisecond s</tt*/
/* They seem to ignore that UT != UTC */

Which parts of that page d0 you believe to deal with the reading and
writing of non-FFF numeric date strings??
The information about the constructor and the various setters
and getters seemed useful. The question involved more than
simply reading and writing date strings.
--

Aug 9 '07 #10

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

Similar topics

1
1571
by: Dave Mann | last post by:
Hi to all those Knowledge Brokers out there! I am trying to get a field to return a date (Next Due date) only if a box is checked (is it planned or unplanned)and Type of Work performed (i.e if DNV add 12 months) so for instance i fill in the fields like so:- Date work done, Description of work, performed by, Type of Maint(select from dropdown, this table has Frequency field), Planned
1
1762
by: John Feeley | last post by:
am tring to add a number of years to a dob. im doing this by adding my date+years*365.26 I get a string of numbers. I then convert the number in the next column to actual date again. I'm getting the correct date. Now I want my criteria on that column to allow me to return only date in a given to from period of my choosing. I try the between_and functions but nothing is returned. I'm guessing it's because the column is still a calculation...
3
4885
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
2
21079
by: markryde | last post by:
Hello, I am trying to add the current date to a file name in python script like thus: import os import sys import rpm import time import datetime
6
2630
by: ninrulz | last post by:
I have created a database that has over 70 queries and over 40k records. I used the OutputTo action to export the queries to Excel. I would like the functionality of adding the date (Month-YY) to each of the Excel file names as they are exported. It seems that the OutputTo action only allows for predetermined names or a prompt for each file. I do not want to type the file names 70+ times and renaming each of the ..xls files afterwards is a...
6
12550
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...
27
2867
by: Rio Liaden | last post by:
Hi all! My database allows all employees to enter their time and get a report at any time. The first screen has a calendar which is locked to the last day of the pay period and that date is the only one currently in place. The user selects his/her name from a dropdown, clicks the calendar, then "Next" to get to the time input screen. There are combo boxes to select the cost code, project, and company name. Separate boxes are available for...
3
1832
by: seepnezorf | last post by:
I keep a database of projects. I have a memo field in which I keep dated notes about the status. Above the memo field is a button called "update date." When I click on the button it adds into the memo field a bullet the date and the dash "• 01-07-2008 -" There is an on click event procedure associated with the button and the code at the back end looks like this: Private Sub Command73_Click() Me.Recent_Update = Me.Recent_Update.Value &...
3
3542
by: janetopps | last post by:
I have a news website, with asp pages, which was on Access, and i upgraded to MySQL, i used Bullzip to transfer the data. It had about 1000 pages, which im now able to pull up on the public side. Im sorting out a few glitches though. Since i upgraded from ms access database to MySQL, i have added about 4 articles to test the new setup. I note some fields aren't being added in the new mySql database for the new 4 records. When i ran the MySQK...
0
10302
Oralloy
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...
0
10136
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 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...
0
9925
tracyyun
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...
0
6723
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();...
0
5372
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...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4036
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
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2867
bsmnconsultancy
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...

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.