Solved

Having trouble with dates

Posted on 2000-02-17
14
164 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
What You Need to Know when Searching for a Webhost Provider
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

623 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