Ask a Question related to Coldfusion Database Access, Design and Development.
-
GoBigOrange #1
Database Query Only Show Current Month Articles
Right now we are having to go in and manually change the date to only show
this month and years articles, but we'd like to change the query so we can
only show this month, year using a variable. Here is the query can someone
tell me what we would need to change it to only show the current months
articles without manually doing it?
WHERE type='news' and date > '07/01/2005' and date < '7/31/2005'
Thank in advance.
GoBigOrange Guest
-
Database driven articles
Hello, I am supernew to ColdFusion and to these forums, and I'm sorry if this is an overly obvious/retarded question. That said: I am... -
Query distinct month and date
ASP 3.0 VB - access We are trying to take a date field and pull the month and year into a drop down menu. I am using access and can format the... -
Current month change
Hello, Total n00b here who needs help. I have a list of weblog (blog) entries in a database which are being retrieved by index.php with a string... -
shortcut to show/hide current layer?
is there a shortcut to show / hide the current layer? thanks felix -
Show" Last view... Day - Month - Date - Year on page.
Hello All; I have just added in a JavaScript function that show that Day - Month - Day - Year On my page. This is going for a look of Last... -
jdeline #2
Re: Database Query Only Show Current Month Articles
I'm sorry, but 07/01/2005 just isn't going to fly. What is the format of the
date field in your database? The current month's articles for this year are
DateFormat(Now(), "yyyymm"), which is what you could be storing in the
database. That gives you 200508 for this month.
jdeline Guest
-
GoBigOrange #3
Re: Database Query Only Show Current Month Articles
We are already doing a query on the database using that code WHERE type='news'
and date > '07/01/2005' and date < '7/31/2005'
I looked at the database in enterprise manager and the data format is 4/2/2005
9:22:29 AM
The problem is, we don't need to manually put the dates in, what would the
code be to pull out the last 30 days
GoBigOrange Guest
-
mxstu #4
Re: Database Query Only Show Current Month Articles
Originally posted by: GoBigOrange
We are already doing a query on the database using that code WHERE type='news'
and date > '07/01/2005' and date < '7/31/2005'
I think the point was that the query above only gives you records "dated"
between 7/2/2005 and 7/30/2005, which is not the entire month of July.
<!--- find all records "dated" within the current month --->
<!--- example: 08/01/2005 and 08/31/2005 --->
<cfset firstOfMonth = CreateDate(Year(Now()), Month(Now()), 1)>
<cfquery name="getNews" datasource="myAccessDSN">
SELECT Type, DateColumn
FROM YourTable
WHERE type='news' AND
dateColumn >= #CreateODBCDate(firstOfMonth)# AND
dateColumn < #CreateODBCDate(DateAdd("m", 1, firstOfMonth))#
</cfquery>
<!--- find all records "dated" in the last 30 days --->
<!--- example: if today is 08/20/2005 .... --->
<!--- returns records "dated" between 07/22/2005 through 08/20/2005 .... --->
<cfquery name="getNews" datasource="myAccessDSN">
SELECT Type, DateColumn
FROM YourTable
WHERE type='news' AND
dateColumn >= #CreateODBCDate(DateAdd("d", -29, Now()))# AND
dateColumn < #CreateODBCDate(DateAdd("d", 1, Now()))#
</cfquery>
mxstu Guest
-
GoBigOrange #5
Re: Database Query Only Show Current Month Articles
Thanks for the code, it worked like a charm!
GoBigOrange Guest
-
GoBigOrange #6
Re: Database Query Only Show Current Month Articles
Okay one more question and I will leave you guys alone! We have a thing that
shows the next home game on the site. What I would like to do is show a summary
of the next 5 home games or perhaps all the home games for the current month.
Here is the query that shows the next home game:
<cfquery name="gameToday" datasource="#mainDSN#"
username="#mainDSNUsername#" password="#mainDSNPassword#">
SELECT *
FROM schedule
WHERE date='#dateformat(now(),'mm/dd/yyyy')#' AND (Score IS NULL or Score =
'') and home = 1 and final != 1
</cfquery>
GoBigOrange Guest
-
mxstu #7
Re: Database Query Only Show Current Month Articles
The next five future games from a specific date.. or the current date? If from
the current date, should it include a game scheduled for the current date?
To show all the games for the current month, you can just adapt the first
query in my example above. It begins with the comment line : <!--- find all
records "dated" within the current month --->
mxstu Guest
-
GoBigOrange #8
Re: Database Query Only Show Current Month Articles
My date format is different on this table, perhaps that is the problem the
dates are formatted like 10/21/2005. I keep getting a processing error. One of
the things is the home has to be 1 so I have a where statement too.
<cfset firstOfMonth = CreateDate(Year(Now()), Month(Now()), 1)>
<cfquery name="games" datasource="#mainDSN#" username="#mainDSNUsername#"
password="#mainDSNPassword#">
SELECT *
FROM schedule
WHERE home = 1
date >= #CreateODBCDate(DateAdd("d", -29, Now()))# AND
date < #CreateODBCDate(DateAdd("d", 1, Now()))#
</cfquery>
GoBigOrange Guest
-
mxstu #9
Re: Database Query Only Show Current Month Articles
> My date format is different on this table, perhaps that is the problem
What database are you using? Is the column a date/time column? What do you> the dates are formatted like 10/21/2005.
mean by the format is different than your other table?
mxstu Guest
-
GoBigOrange #10
Re: Database Query Only Show Current Month Articles
the column is called date and when we put the schedules in we enter the date of
the game like 10/21/2005. Probably should have been called something else, but
someone else did it! 10/21/2005 is a sample of a date in the column.
GoBigOrange Guest
-
mxstu #11
Re: Database Query Only Show Current Month Articles
You didn't say whether or not it is a date/time column.
Also, "Date" is a reserved word, so using it as a column name will likely cause problems.
mxstu Guest
-
mxstu #12
Re: Database Query Only Show Current Month Articles
>Also, "Date" is a reserved word, so using it as a column name will likely
cause problems.
I take that back. You can use "Date" as a column name in SQL Server database,
but using another name would be better.
mxstu Guest
-
GoBigOrange #13
Re: Database Query Only Show Current Month Articles
that's what I was afraid of. time to rename column.
GoBigOrange Guest
-
mxstu #14
Re: Database Query Only Show Current Month Articles
Did you see my question?
You didn't say whether or not it is a date/time column.
mxstu Guest
-
GoBigOrange #15
Re: Database Query Only Show Current Month Articles
no, somebody has named the column date. And they should have called it gamedate or something. The newletter using a real data field that timestamps.
GoBigOrange Guest
-
mxstu #16
Re: Database Query Only Show Current Month Articles
I'm talking about the column data type. For example, sql server uses the
"date/time" data type to store dates, "varchar" to and "char" to text
characters, etc... Anyway, I think your problem may be that you're missing an
AND in your statement:
SELECT *
FROM schedule
WHERE home = 1 missing an AND here ....
date >= #CreateODBCDate(firstOfMonth)# AND
date < #CreateODBCDate(DateAdd("m", 1, firstOfMonth))#
mxstu Guest
-
mxstu #17
Re: Database Query Only Show Current Month Articles
Originally posted by: GoBigOrange
no, somebody has named the column date. And they should have called it
gamedate or something. The newletter using a real data field that timestamps.
The response was not quite clear ;-) If "Schedule.Date" is NOT a "date/time"
column.... then you are correct... using #CreateODBCDate()# will not work
because it is intended for use with "date/time" columns. If this is the case,
you should consider changing the column's data type to "date/time". Dates
should be stored as dates and not text. Just be aware that the change may
affect other queries that insert into or update this field.
mxstu Guest
-
GoBigOrange #18
Re: Database Query Only Show Current Month Articles
The column data time is datetime ....sorry. :-)
GoBigOrange Guest
-
mxstu #19
Re: Database Query Only Show Current Month Articles
There should not be any problem if the data type IS "date/time". Did you
correct the syntax error I mentioned in the original query?
SELECT *
FROM schedule
WHERE home = 1 AND <--- missing an AND here
date >= #CreateODBCDate(firstOfMonth)# AND
date < #CreateODBCDate(DateAdd("m", 1, firstOfMonth))#
mxstu Guest
-
GoBigOrange #20
Re: Database Query Only Show Current Month Articles
Yeah, the and sort of helps, huh? That did the trick. Thanks!
GoBigOrange Guest



Reply With Quote

