Skip to main content
Inspiring
August 10, 2006
Question

date format!!

  • August 10, 2006
  • 4 replies
  • 722 views
Hi
i have news page where i want the recent 5 months to be listed on the left hand side and when you click on a month the stories load up on the right hand side of the same page.

i need some coldfusion code which would only bring up the month of the date. for example the date field in the database is yyyy-mm-dd, i want just the month to be displayed and not the year or the day.

thanks
    This topic has been closed for replies.

    4 replies

    Kamesh192Author
    Inspiring
    August 11, 2006
    hi
    this is what ive put in my news page, is this correct:
    <span class= "<cfoutput>#rsProject.projectID#</cfoutput>"> <a href="news2.cfm" title="Web" target="_self">
    <div> <CFSET startdate=CreateDate(Form.year, Form.month, 1)>
    <cfoutput>#MonthAsString(Month(rsNews.Date))#</cfoutput><BR> </div>
    </a></span>

    i dont think it right as i have no forms on my page, the months that a user selects are simple links.

    this is my sql query, could someone tell me if its right?
    "date" is the date field in my database

    SELECT *
    FROM tbNews
    WHERE date >= #startdate# AND date < #DateAdd("m", 1, startdate)#

    could someone help me, its hard to undertand what i am doing wrong because of my inexperience.

    thanks
    Inspiring
    August 14, 2006
    If you don't have a form, you can pass parameters with the URL. For example, if you want a link that shows stories for July 2006, your URL could be showstories.cfm?yr=2006&mo=7

    Then you set the date with the URL parameters:

    <CFSET startdate=CreateDate(URL.yr, URL.mo, 1)>

    This will set the date to July 1, 2006 at 00:00.
    Kamesh192Author
    Inspiring
    August 15, 2006
    hi

    thanks for the information.

    im still having some problems! sorry
    i need the months and the stories to be displayed on 1 page (the same page), if this possible? also ive placed <CFSET startdate=CreateDate(URL.yr, URL.mo, 1)> on my page and now an error appears before the page is loaded (www.pixelwork.com/2006/news2.cfm). ??

    if i cant have the months and the stories on the same page, then i can make 2 separate pages- this not a problem, just need to know if i can have them both on the same page.


    i understand passing the URL variables, however i am a bit stuck on how to get my query to read them.

    my sql does not work and is shown below.
    SELECT *
    FROM tbNews
    WHERE date = #URL.yr# AND #URL.mo#

    thanks everyone
    Kamesh192Author
    Inspiring
    August 11, 2006
    hello

    sorry im still new to web development, what parameter do i have to attach to month? and what do i make the target query look for in the url?

    sorry if my question seems to too basic.
    the page online at www,pixelwork.com/2006/news2.cfm. i have made the database pull the month in on the right hand side. please ignore the links motion and and identity. the stories then are to be loaded in the space next to the months (the off white coloured)

    hope this makes sense.
    thanks

    Inspiring
    August 11, 2006
    In that case, dempster has given you the general idea. You just have to add some logic to assign a year to the month selected. The year you select depends on the business rules of your application.
    Inspiring
    August 10, 2006
    Kamesh192Author
    Inspiring
    August 10, 2006
    hi

    Thanks adam, that exactly what i was looking for.

    Got another related question. im trying to create a SQL query to filter results byt month. so basically when the user select the month July , then i want all the July news stories to apear. anyone has any ideas for the "where" statement?

    thanks all
    Inspiring
    August 10, 2006
    If you have 2 variables from your form for year and month, you can create a date object for the start of the month this way:

    <CFSET startdate=CreateDate(Form.year, Form.month, 1)>

    CreateDate makes date/time object with the time set at 00:00. Then you can query this way:

    WHERE newsdate >= #startdate# AND newsdate < #DateAdd("m", 1, startdate)#

    DateAdd with "m" will add one month to the start date.