473,789 Members | 2,732 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
17 3452
In comp.lang.javas cript message <f9*********@dr n.newsguy.com>, Wed, 8
Aug 2007 16:40:17, Lee <RE************ **@cox.netposte d:
>Thomas 'PointedEars' Lahn said:
>...
Can you explain how your ludicrous multiplication method works
if the resulting date is earlier than the 10th of the month?
The multiplication method is currently good for generating YYYYMMDD.

It is not good for DDMMYYYY or 8-digit FFF.

OTOH, given that separators are required, consider

d = new Date("1234/01/02") // 1234 Jan 2
X =
String(d.getFul lYear()*1e4 + d.getMonth()*1e 2 + d.getDate() + 100)
.replace(/(\d{4})(\d\d)(\ d\d)/, "$3/$2/$1");

Change the \d{4} to \d+ and the code will be shorter and last longer.

--
(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 #11
In comp.lang.javas cript message <fZ************ **@invalid.uk.c o.demon.me
rlyn.invalid>, Fri, 10 Aug 2007 21:04:47, Dr J R Stockton
<jr*@merlyn.dem on.co.ukposted:
>In comp.lang.javas cript message <46************ **@PointedEars. de>, Fri,
10 Aug 2007 09:27:13, Thomas 'PointedEars' Lahn <Po*********@we b.de>
posted:
>>Dr J R Stockton wrote:
>>Javascript lacks specific syntax for creating a Date Object of a given
Ordinal Date;

Define "Ordinal Date". If you mean something like the number of
millisecond s since the beginning of the UNIX era, then

It is defined in ISO 8601, which is IIRC released as an EN and possibly
a DIN. Alas, 8601 is AFAIK not free (unlike 8602); but the definition
is easily found by Google.
Correction : I had forgotten that ISO 8601:2004 was in fact available
free in PDF, from ISO, <http://isotc.iso.org/livelink/livelink?func=ll&o
bjId=4020763&ob jAction=browse& sort=nameprobab ly; and from OMG -- links
are on my site, but I forget which I actually used. It seems that ISO
do allow one to pay for the paper version and for the PDF, if one so
wishes.

--
(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 15 '07 #12

On Aug 8, 12: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.
I'll try a more explicit approach.

The first step is to add 50 days to the date object.

// get the date.
var date = new Date();
var dayOfMonth = date.getDate()) ; // This API method "getDate" should
be renamed to "getDayOfMonth" .

// add 50 days.
date.setDate( dayOfMonth + 50 );
Any help would be appreciated.
Write a unit test to verify each step.

Here is a horrible ad hoc test:
javascript:aler t(new Date (new Date().setDate( new Date().getDate( ) +
50 ) - ( 50 * 24 * 60 * 60 * 1000 ) ) )

Garrett

Aug 23 '07 #13
The problem appears that there is no standard way of formatting a Date
to a customized string.

It seems possible to format a Date string using a RegExp, but the Date
string cannot be guaranteed to be in a specific format.

I would like to see this added to ES4.

var s = "EEE, MMM d, yyyy"
var df = DateFormat( s );
var formattedDay df.format( new Date() ); // Thu, Aug 23, 2007.

http://java.sun.com/j2se/1.5.0/docs/...ateFormat.html
Aug 23 '07 #14
dh**********@gm ail.com wrote:
[...]
date.setDate( dayOfMonth + 50 );
You are a *little* late. <Xn************ ********@194.10 9.133.242>
PointedEars
--
var bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16
Aug 24 '07 #15
In comp.lang.javas cript message <11************ *********@z24g2 000prh.goo
glegroups.com>, Thu, 23 Aug 2007 23:48:11, "dh**********@g mail.com"
<dh**********@g mail.composted:
>The problem appears that there is no standard way of formatting a Date
to a customized string.

It seems possible to format a Date string using a RegExp, but the Date
string cannot be guaranteed to be in a specific format.

I would like to see this added to ES4.

var s = "EEE, MMM d, yyyy"
var df = DateFormat( s );
var formattedDay df.format( new Date() ); // Thu, Aug 23, 2007.

http://java.sun.com/j2se/1.5.0/docs/...ateFormat.html
Since that is Java, and this is a Javascript newsgroup, ISTM that you
have a severe sagacity deficiency.
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 24 '07 #16
In comp.lang.javas cript message <11************ *********@r23g2 000prd.goo
glegroups.com>, Thu, 23 Aug 2007 23:43:35, "dh**********@g mail.com"
<dh**********@g mail.composted:
>Here is a horrible ad hoc test:
javascript:ale rt(new Date (new Date().setDate( new Date().getDate( ) +
50 ) - ( 50 * 24 * 60 * 60 * 1000 ) ) )
That will, at present, show the present date and time.

But change both instances of 50 to 130, and it will probably show you an
hour after present time, but might show the present time or an hour (or
half an hour, but that's unlikely) before present time.

Until you understand that, it would be better if you did not try to
answer Javascript date questions.

--
(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 24 '07 #17
Dr J R Stockton said the following on 8/24/2007 4:24 PM:
In comp.lang.javas cript message <11************ *********@z24g2 000prh.goo
glegroups.com>, Thu, 23 Aug 2007 23:48:11, "dh**********@g mail.com"
<dh**********@g mail.composted:
>The problem appears that there is no standard way of formatting a Date
to a customized string.

It seems possible to format a Date string using a RegExp, but the Date
string cannot be guaranteed to be in a specific format.

I would like to see this added to ES4.

var s = "EEE, MMM d, yyyy"
var df = DateFormat( s );
var formattedDay df.format( new Date() ); // Thu, Aug 23, 2007.

http://java.sun.com/j2se/1.5.0/docs/...ateFormat.html

Since that is Java, and this is a Javascript newsgroup, ISTM that you
have a severe sagacity deficiency.
If you had bothered to read, and comprehend, the line preceding the code
posted you would have realized some things that you are either too
arrogant or too ignorant to admit, possibly - and probably - both.

--
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 25 '07 #18

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
21081
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
12559
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
3544
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
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10200
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...
1
10139
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9984
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
9020
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6769
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
5418
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
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4093
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 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.