Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Displaying dates before today's date

Participant ,
May 08, 2008 May 08, 2008
Hi,
How can I display dates before the current date. The default date needs to be the current date, but rest of the dates need to be in the past. Here's my code:
Thanks!
486
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
May 08, 2008 May 08, 2008
quote:

Here's my code
??? looks like an oops.....
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 08, 2008 May 08, 2008
Indeed!
Here's my code (pasting again):
<cfset todaysdate=DateFormat(today, "mmmm, d yyyy")>
<select name="mymonth">
<cfloop from="1" to="12" index="i">
<option value="#i#" <cfif i EQ Month(todaysdate)>Selected</cfif>>#monthAsString(i)#
</cfloop>
</select>
<select name="myday">
<cfloop from="1" to="31" index="i">
<option value="#i#" <cfif i EQ Day(todaysdate)>Selected</cfif>>#(i)#
</cfloop>
</select>
<select name="myyear">
<cfloop from="2005" to="#(Year(Now())+5)#" index="i">
<option value="#i#" <cfif i EQ Year(todaysdate)>Selected</cfif>>#(i)#
</cfloop>
</select>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 08, 2008 May 08, 2008
quote:

Originally posted by: jenn
Hi,
How can I display dates before the current date. The default date needs to be the current date, but rest of the dates need to be in the past. Here's my code:
Thanks!


Take a look at the dateadd function

dateadd("datepart", number, "date")

If you use a negative number it's like subtracting so for example dateadd(yyyy,-1,now()) returns a date exactly 1 year ago

HTH
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 08, 2008 May 08, 2008
quote:

Originally posted by: jenn
Hi,
How can I display dates before the current date. The default date needs to be the current date, but rest of the dates need to be in the past. Here's my code:
Thanks!

The rest of what dates?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 08, 2008 May 08, 2008
I have a drop down for each date part (e.g. month, day, year), and the default is the current date. So, May, 8, 2008 will be the default. Year choice will be 2008, 2007, 2006 etc. I'm trying to restrict users to only selecting the current date or past dates, no future dates. Does this make sense?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 08, 2008 May 08, 2008
jenn wrote:
> I have a drop down for each date part (e.g. month, day, year), and the default
> is the current date. So, May, 8, 2008 will be the default. Year choice will
> be 2008, 2007, 2006 etc. I'm trying to restrict users to only selecting the
> current date or past dates, no future dates. Does this make sense?
>

Then try:

<cfloop from="#year(Now())#" to="#(Year(Now())-5)#" index="i" step="-1">
<option value="#i#" <cfif i EQ Year(todaysdate)>Selected</cfif>>#(i)#
</cfloop>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 08, 2008 May 08, 2008
LATEST
i think what you need is just client-side and sever-side validation of
selected date.
Ian's code will limit the YEARS to current and prior years, but your
users will still be able to select a day in the future if they select a
month or date which are in the future in current year.

use Ian's code to limit selectable years, validate the full submitted
date to make sure it is not in the future, and display alert if the
selected date is gt current date. make sure you take into account user's
timezone and server's timezone if your users can come from around the
world: your server's time may be behind your user's time...


Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources