Solved

Having trouble with dates

Posted on 2000-02-17
14
151 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now