• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

Get day from date

My website shows dates of scheduled events from database, but I need to add day(mon, tues..) on the page as well. I need a reference code or something so that the 'events' page automatically displays day along with dates.

ex.
Saturday, June 21, 2003
Biotechnology Forum

I have a calendar code here. But I dont know how to get a matched day.

 <CFPARAM NAME = "month" DEFAULT = "#DatePart('m', Now())#">
  <CFPARAM NAME = "year" DEFAULT = "#DatePart('yyyy', Now())#">
  <CFPARAM NAME = "currentday" DEFAULT = "#DatePart('d', Now())#">
  <CFPARAM NAME = "startmonth" DEFAULT = "#DatePart('m', Now())#">
  <CFPARAM NAME = "startyear" DEFAULT = "#DatePart('yyyy', Now())#">

  <!--- Set the requested (or current) month/year date and determine the number of days in the month. --->
  <cfset ThisMonthYear = CreateDate(year, month, '1')>
  <cfset Days = DaysInMonth(ThisMonthYear)>

  <!--- Set the values for the previous and next months for the back/next links. --->
  <cfset LastMonthYear = DateAdd('m', -1, ThisMonthYear)>
  <cfset LastMonth = DatePart('m', LastMonthYear)>
  <cfset LastYear = DatePart('yyyy', LastMonthYear)>
  <cfset NextMonthYear = DateAdd('m', 1, ThisMonthYear)>
  <cfset NextMonth = DatePart('m', NextMonthYear)>
  <cfset NextYear = DatePart('yyyy', NextMonthYear)>

  <table border = "1" bgcolor="#cccccc">
     <tr>
         <td ALIGN = "center" >
         <!--- Display the current month/year as well as the back/next links. --->
         <CFOUTPUT>
         <nobr>
            <A HREF = "calendar.cfm?month=#LastMonth#&year=#LastYear#" class="calendar"><<</A>
            <font class="caltexthighlight">#MonthAsString(month)# #year#</font>
            <A HREF = "calendar.cfm?month=#NextMonth#&year=#NextYear#" class="calendar">>></A>
         </CFOUTPUT><br><br>
         
        <table border = "1" cellspacing=0 cellpadding=3>
         <!---
                Display the day of week headers.  I've truncate the values to display only the first three letters of each day of the week.
          --->
             <tr class="calendarheader">
                <CFLOOP FROM = "1" TO = "7" INDEX = "LoopDay">
                   <CFOUTPUT>
                     <td WIDTH = "15" ALIGN = "center">#Left(DayOfWeekAsString(LoopDay), 1)#</td>
                   </CFOUTPUT>
                 </CFLOOP>
             </tr>
          <!---
                 Set the ThisDay variable to 0.  This value will remain 0 until the day of the week on which the first day of the month falls on is reached.
            --->
             <cfset ThisDay = 0>
             <!--- Loop through until the number of days in the month is reached.  --->
             <CFLOOP CONDITION = "ThisDay LTE Days">
                <tr class="calendar">
          <!--- Loop through each day of the week. --->
          <CFLOOP FROM = "1" TO = "7" INDEX = "LoopDay">
          <!---
            If ThisDay is still 0, check to see if the current day of the week in the loop
            matches the day of the week for the first day of the month.
            If the values match, set ThisDay to 1.
            Otherwise, the value will remain 0 until the correct day of the week is found.
          --->
              <cfif ThisDay IS 0>
                 <cfif DayOfWeek(ThisMonthYear) IS LoopDay>
                    <cfset ThisDay = 1>
                 </cfif>
              </cfif>
          <!---
             If the ThisDay value is still 0, or it is greater than the number of days in the month,
              display nothing in the column. Otherwise, display the day of the month and increment the value.
          --->
            <cfif (ThisDay IS NOT 0) AND (ThisDay LTE Days)>
                <CFOUTPUT>
                <!--- I choose to highlight the current day of year using an IF-ELSE. ---->
                    <cfif (#ThisDay# EQ #currentday#) AND (#month# EQ #startmonth#) AND (#year# EQ #startyear#)>
                    <td ALIGN = "center">
                      <cfset dayview = #dateformat(createdate(#year#, #month#, #thisday#), "mm/dd/yyyy")#>
                           <font class="calendartoday">#ThisDay#</font>
                    </td>
                 <cfelse>
                    <td ALIGN = "center">
                       <cfset dayview = #dateformat(createdate(#year#, #month#, #thisday#), "mm/dd/yyyy")#>
                       <font class="calendar">#ThisDay#</font>
                    </td>
                 </cfif>
                 </CFOUTPUT>
                 <cfset ThisDay = ThisDay + 1>
              <cfelse>
                 <td></td>
              </cfif>
         </CFLOOP>
       </tr>
     </CFLOOP>
     </table>
     </td>
    </tr>
</table>
0
gotchaman
Asked:
gotchaman
  • 3
  • 2
  • 2
1 Solution
 
anandkpCommented:
hi - did u try dateformat function ?

let me know

K'Rgds
Anand
0
 
cdillonCommented:
Anand is right, you can use

dateformat(your_date_variable_here,'dddd, mmmm d, yyyy')

To display the full name of the day and the full name of the month (Saturday, June 21, 2003)
0
 
gotchamanAuthor Commented:
oh my... I didn't even think that'd work. How does it work though? Is there updated calendar application or something installed in CF?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
gotchamanAuthor Commented:
and of course once i accept an answer no one gives a damn any longer.
0
 
cdillonCommented:
coldfusion has date calculation functions like dateadd, ect.
0
 
gotchamanAuthor Commented:
and of course once i accept an answer no one gives a damn any longer.
0
 
anandkpCommented:
dont worry - abt formatting - ask me what u want & u'll get it - even thou ur already awarded the points

let me know

K'Rgds
Anand
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now