Solved

Having trouble with dates

Posted on 2000-02-17
14
160 Views
Last Modified: 2013-12-24
I have a form with a date input box.
<input type="text" name="myDate">
My CF code to manipulate this is:
<cfset userDate = trim(form.myDate)>
 <cfif isDate(userDate)>
  <cfset dbDate = dateFormat(userDate, "dd/mm/yy")>
 </cfif>

Now, the problem is: if I enter the date for 4 February 2000 as 04/02/2000, #dbDate# comes out as 02/04/00. ..and if I enter 02/04/2000, it comes out as 04/02/00. There is no problem if the dd value is greater than 12.

Since I suspected it to be a locale problem, of which my default is English (US), SetLocale("English (UK)") didn't solve the problem, neither did any other supported locale managed to change this.

How can I solve this problem?
0
Comment
Question by:chaduka
  • 6
  • 6
  • 2
14 Comments
 
LVL 5

Expert Comment

by:nathans
ID: 2531718
myDate input '02/04/2000'

<input type="text" name="myDate">


======================================

 <cfif isDate(myDate)>
  <cfset DisplayDate1 = dateFormat(userDate, "dd/mm/yyyy")>
 </cfif>

 <cfif isDate(myDate)>
  <cfset DisplayDate2 = dateFormat(userDate, "mm/dd/yyyy")>
 </cfif>

 <cfif isDate(myDate)>
  <cfset DisplayDate3 = dateFormat(userDate, "mmmm dd, yyyy")>
 </cfif>

<cfoutput>
#DisplayDate1#<BR>
#DisplayDate2#<BR>
#DisplayDate3#<BR>
</cfoutput>


=====================================

OUTPUT WOULD BE

04/02/2000
02/04/2000
February 04, 2000

Does this answer your problem...???
0
 
LVL 1

Author Comment

by:chaduka
ID: 2531778
No, houw would you validate that the line <<< myDate input '02/04/2000' >>>
does read 4 February, and not 2 April?

0
 
LVL 5

Expert Comment

by:nathans
ID: 2531939
I see I see said the blind man who picked up the hammer and saw.


hmmmmm......

I guess because of the way the dateformat is...


Well you would have to do it the hard way... I think... I will check for other solutions as well but...

What you need is
1. To Request the date either in
   mm/dd/yyyy or dd/mm/yyyy

2. Once you know which way the person is going to enter the date then you can use mm/dd/yyyy like you normally would and if you choose dd/mm/yyyy you can select the first section to the left or the / and second section after the / and the third after the /.  Once you have done this
0
Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

 
LVL 5

Expert Comment

by:nathans
ID: 2531965
Then you can use the data...

3. Another choice is to create drop downs...

Day   Month  Year

Does this help?

I will go try and find out otherwise

--------------

You have to request the date in either
mm/dd/yy OR dd/mm/yy format or you will not be able to know which one they meant... unless you checked for 12 or less and using javascript and popped up to ask a question which one they are useing.  Since the WEB is World Wide...

Sorry, alot of the web was created with US standards when we are not the majority of the people alive on the planet.  

0
 
LVL 1

Author Comment

by:chaduka
ID: 2531979
Yeah, so I have figured out. But the funny thing is if then someone enters a date like 21/04/2000, we don't have irony.

The only solution, so it seems, is to ask the user to enter the date as dd-mmm-yyyy format, that is, type the month as text. This way, there is no confusion. dateFormat() won't switch the date and month.

*sigh*
0
 
LVL 1

Author Comment

by:chaduka
ID: 2531985
Ooops, you submitted your last comment just before I mailed mine.

Ok, tx nathans. Will keep my eyes open for any easier solutions.
0
 
LVL 5

Expert Comment

by:nathans
ID: 2532070
I checked with Allaire and NO LUCK...

Sorry

Forgive us US folks for not creating a web that made it where you could choose both ways.
0
 
LVL 5

Expert Comment

by:nathans
ID: 2532853
Still looking around

Nathan Stanford
Mr ColdFusion
------------------------------------
CFTips+ a FREE ColdFusion e-ZINE
subscribe-cftips@nsnd.com
0
 
LVL 37

Expert Comment

by:meverest
ID: 2533682
what about:

Enter Date:<select name=day>
<cfloop from=1 to=31 index=num>
<option value=#num#>#num#
</cfloop>
/
<select name=month>
<cfloop from=2000 to=2020 index=num>
<option value=#num#>#num#
</cfloop>
/
<select name=year>
<cfloop from=1 to=31 index=num>
<option value=#num#>#num#
</cfloop>


then <cfset date="#day#/#month#/#year#">

that way, no confusion..?

cheers.


0
 
LVL 1

Author Comment

by:chaduka
ID: 2533841
Yeah, meverest, that solution seems close to total control, if I will have DateFormat() get the month as mmm, otherwise if I just give it a number < 12, CF is bound to switch my dates again!!
0
 
LVL 37

Accepted Solution

by:
meverest earned 50 total points
ID: 2537397
(hey, i just notice that goof i made with the above cf code snippet - oops! ;-)

anyway, you are right, but you could do the month part like:

<select name=month>
<cfloop list="Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec" index=mon>
<option value=#mon#>#mon#
</cfloop>

then your dat formats can't make that mistake ;-)

cheers.


0
 
LVL 5

Expert Comment

by:nathans
ID: 2549090
You might as well give one of us the points as there is no way you can know with out coding in the Month.

Nathan

0
 
LVL 1

Author Comment

by:chaduka
ID: 2549341
I am still looking for a best solution. From the allaire forums, I have heard that I can use:

<cfinput .... validate="eurodate" ...>

I haven't tried it as yet. I would want to exhaust more options to conquering this thing, rather than rush to award points, which is a secindary objective for this place. Sharing knowledge is the primary thing, no? I stand to be corrected.
0
 
LVL 1

Author Comment

by:chaduka
ID: 2564537
I decided to give meverest the points because he came with the idea of splitting the date form to make the user select the day/month. (I wish these points could be split).

Thanx nathans, your help was great too!
0

Featured Post

Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
AWS Advice on using WHM/cPanel 1 87
exchange 2010 turning off 3des ciphers 2 426
Linux Hosting 16 74
How can i point a subdomain to directory? 5 38
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question