473,722 Members | 2,430 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to instantiate a date object with UK format date??

hi

I have written javascript for comparing two dates in US format and
finding out whether the start date is greater than the end date and
vice versa.

In this attempt i have instantiated the date object with the date
string which the user inputs from a pop up calendar.

somewhat like this..........

var startdate= new Date(document.M Form.startDate. value);

Where MForm = form name
startDate= The name of the TextField where i fetch the date
from the user
in the US format(MM/DD/YYYY).

All my compare logic is based on the US format dates, which is
somewhat like this..........

var startdate= new Date(document.M Form.startDate. value);
var enddate=new Date(document.M Form.endDate.va lue);
var today=new Date();
var one_day=1000*60 *60*24;
var end_start_diff =
Math.ceil((endd ate.getTime()-startdate.getTi me())/(one_day));

if((end_start_d iff < 0))
{
alert(" End date should be greater than Start date");
document.MForm. endDate.focus() ;
return(false);
}

this logic works fine with US dates. But i realised that the same
code would not work if I accpet UK format dates from the
user.......b'co s

new Date("02/11/2004") US Format (MM/DD/YYYY) gives Feb 11,
2004
but... new Date("11/02/2004") UK Format (DD/MM/YYYY) gives Nov 2,
2004

......and this is what is causing the problem.

The soln what i have thought is to change the UK format date to US
format in the date.
But i need to know if a Date Object in javascript can be instantiated
with the UK format of date as the parameter??

ex: new Date("11/02/2004") should gimme Feb 11, 2004. Is there any
method i can do this. If not what are the other easy methods to solve
this problem??

Thanks in advnace for helping.

Regards

Amith
Jul 20 '05 #1
2 5062
On 11 Feb 2004 05:47:58 -0800, amith <it*******@yaho o.co.in> wrote:
The soln what i have thought is to change the UK format date to US
format in the date.
But i need to know if a Date Object in javascript can be instantiated
with the UK format of date as the parameter??

ex: new Date("11/02/2004") should gimme Feb 11, 2004. Is there any
method i can do this. If not what are the other easy methods to solve
this problem??


If you site is international, it would be a wise decision to use the
international date format, yyyy-mm-dd. There can be little confusion here.
Alternatively, you can split the one field into three, marking each
clearly as day, month, and year.

Dr Stockton, a regular poster here, has produced comprehensive information
on date and time manipulation. One of the pages, covering input and
validation, can be found here:

http://www.merlyn.demon.co.uk/js-date4.htm

Mike
Dr Stockton's JavaScript pages:

http://www.merlyn.demon.co.uk/js-index.htm

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2
JRS: In article <op************ **@news-text.blueyonder .co.uk>, seen in
news:comp.lang. javascript, Michael Winter <M.******@bluey onder.co.invali
d> posted at Wed, 11 Feb 2004 14:08:33 :-
ex: new Date("11/02/2004") should gimme Feb 11, 2004. Is there any
method i can do this. If not what are the other easy methods to solve
this problem??


If you site is international, it would be a wise decision to use the
internationa l date format, yyyy-mm-dd. There can be little confusion here.


Since new Date("2004-02-11") -> NaN
but new Date("2004/02/11") -> Date Object holding start of
local today
ISTM that, if the date is not to be validated, the latter form is
better.

If it is to be validated, one can easily allow [-] [/] [-/] [\.] etc. as
separators, and can also require that the second separator matches the
first.
In the code shown, the OP only needs
if (enddate<=start date) <complain>
He seems inconsistent as respects the effect of having equal dates and
the wording of the complaint.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
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.
Jul 20 '05 #3

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

Similar topics

8
3032
by: Dennis M. Marks | last post by:
What is the maximum valid date range for the date(yyyy,mm,dd) function. -- Dennis M. Marks http://www.dcs-chico.com/~denmarks/ Replace domain.invalid with dcsi.net -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
4
3451
by: peashoe | last post by:
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
1
5511
by: Keith Chadwick | last post by:
Been trying to use the ms:format-date() in one of my transformations. I have all of the necessary declarations in my xml as in <?xml version="1.0" ?> <data xml:space="default" xmlns:dt="urn:schemas-microsoft-com:datatypes"> myxml... </data>
13
3014
by: ahjiang | last post by:
Hi all, Need some help here. How do i create a javascript date object with the format (yyyy:mm:dd hh:mm:ss) do i need to parse it to achieve that? appreciate any inputs
7
6819
by: Richiep | last post by:
I am trying to get a UK format date of dd/mm/yyyy. Why does the following subroutine not return a valid date in a web form? The date returned is #12:00:00 AM# but the date I entered into the text box was 24/06/2006. The other solution I have tried is given by the following two lines that do not compile because a value of date type cannot be converted to datetime:
8
5405
by: libsfan01 | last post by:
how can i use regular expressions to ensure a mysql format date entry in a text field? thanks marc
10
12444
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;} }
27
6884
by: RobG | last post by:
I was investigating a function to determine whether daylight saving was being observed on a particular date (given the platform's regional settings) and came across a suggestion at merlyn.com to test the time zone offset on a variety of dates to see if it changes. Based on that, I developed the following checkDST() function which, as far as I can tell, should be sufficient. It checks either the date passed to it or the current date with...
4
2308
by: Tony B | last post by:
I'm looking to convert a string in "dd/MM/yy" format into a date object. How do I go about this ?
0
8863
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9384
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
9238
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
9157
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
9088
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
8052
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
4502
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...
1
3207
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
3
2147
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.