?
Solved

Get day from date

Posted on 2003-02-21
7
Medium Priority
?
202 Views
Last Modified: 2013-12-24
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
Comment
Question by:gotchaman
[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
  • 3
  • 2
  • 2
7 Comments
 
LVL 17

Accepted Solution

by:
anandkp earned 200 total points
ID: 7994475
hi - did u try dateformat function ?

let me know

K'Rgds
Anand
0
 
LVL 3

Expert Comment

by:cdillon
ID: 7994886
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
 

Author Comment

by:gotchaman
ID: 7995008
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
Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

 

Author Comment

by:gotchaman
ID: 7995381
and of course once i accept an answer no one gives a damn any longer.
0
 
LVL 3

Expert Comment

by:cdillon
ID: 7995424
coldfusion has date calculation functions like dateadd, ect.
0
 

Author Comment

by:gotchaman
ID: 7995634
and of course once i accept an answer no one gives a damn any longer.
0
 
LVL 17

Expert Comment

by:anandkp
ID: 7997604
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

762 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