0
Todays date in MS SQL
New Here
,
/t5/coldfusion-discussions/todays-date-in-ms-sql/td-p/477947
Jan 11, 2008
Jan 11, 2008
Copy link to clipboard
Copied
Hi, I know this is kinda a noob questions but i just cant
figure it out.
I have a query that wants to pull all of todays data. No matter wht i use i cant seem to pull it out of the db.
I have MS SQL 2000 and CF 7.
My Where statement is as follows:
where paymentdate = #CreateODBCDate(now())#
I have also tried just now() and i have even tried this:
<cfset dttoday = CreateDate(
Year( dtNow ),
Month( dtNow ),
Day( dtNow )
) />
Then: where paymentdate = #CreateODBCDate(dttoday)#
No matter what i do i cant get anything to pull TODAYS info out of the DB.
FYI, in another query i can pull all of the data for the past 7 days like this:
where paymentdate Between #CreateODBCDate(DateAdd("d", -6, Now()))# AND #CreateODBCDate( dateadd("d",1,now()))#
And that works just fine. it even pulls todays data out correctly.
I just want only TODAYS data.
Any help would be appreciated.
Thanks
I have a query that wants to pull all of todays data. No matter wht i use i cant seem to pull it out of the db.
I have MS SQL 2000 and CF 7.
My Where statement is as follows:
where paymentdate = #CreateODBCDate(now())#
I have also tried just now() and i have even tried this:
<cfset dttoday = CreateDate(
Year( dtNow ),
Month( dtNow ),
Day( dtNow )
) />
Then: where paymentdate = #CreateODBCDate(dttoday)#
No matter what i do i cant get anything to pull TODAYS info out of the DB.
FYI, in another query i can pull all of the data for the past 7 days like this:
where paymentdate Between #CreateODBCDate(DateAdd("d", -6, Now()))# AND #CreateODBCDate( dateadd("d",1,now()))#
And that works just fine. it even pulls todays data out correctly.
I just want only TODAYS data.
Any help would be appreciated.
Thanks
TOPICS
Database access
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Mentor
,
/t5/coldfusion-discussions/todays-date-in-ms-sql/m-p/477948#M43380
Jan 11, 2008
Jan 11, 2008
Copy link to clipboard
Copied
GETDATE
Returns the current system date and time in the Microsoft® SQL Server™ standard internal format for datetime values.
Syntax
GETDATE ( )
Return Types
datetime
Remarks
Date functions can be used in the SELECT statement select list or in the WHERE clause of a query.
In designing a report, GETDATE can be used to print the current date and time every time the report is produced. GETDATE is also useful for tracking activity, such as logging the time a transaction occurred on an account.
Examples
A. Use GET DATE to return the current date and time
This example finds the current system date and time.
SELECT GETDATE()
Phil
Returns the current system date and time in the Microsoft® SQL Server™ standard internal format for datetime values.
Syntax
GETDATE ( )
Return Types
datetime
Remarks
Date functions can be used in the SELECT statement select list or in the WHERE clause of a query.
In designing a report, GETDATE can be used to print the current date and time every time the report is produced. GETDATE is also useful for tracking activity, such as logging the time a transaction occurred on an account.
Examples
A. Use GET DATE to return the current date and time
This example finds the current system date and time.
SELECT GETDATE()
Phil
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/todays-date-in-ms-sql/m-p/477949#M43381
Jan 11, 2008
Jan 11, 2008
Copy link to clipboard
Copied
If your paymentdate values have time components greater than
"00:00", change this:
Then: where paymentdate = #CreateODBCDate(dttoday)#
to this
Then: where paymentdate >= #CreateODBCDate(dttoday)#
Then: where paymentdate = #CreateODBCDate(dttoday)#
to this
Then: where paymentdate >= #CreateODBCDate(dttoday)#
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
TonyP
AUTHOR
New Here
,
/t5/coldfusion-discussions/todays-date-in-ms-sql/m-p/477950#M43382
Jan 11, 2008
Jan 11, 2008
Copy link to clipboard
Copied
Ok, im still confused. How do you use a SELECT statement in a
query where you have a WHERE looking for a date.
For example, here is my actual query:
SELECT tblpayments.for_auction, tblpayments.txn_type, tblpayments.paymentdate, tblpayments.payment_id, tblpayments.mc_gross, tblpayments.mc_fee, tblitems.item_price, tblitems.item_name, tblcustomers.Cust_First, tblcustomers.Cust_Last
FROM (tblitems INNER JOIN tblpayments ON tblitems.txn_id = tblpayments.txn_id) LEFT JOIN tblcustomers ON tblpayments.customer_id = tblcustomers.Cust_ID
where paymentdate = #CreateODBCDate(now())#
AND payment_status = 'Completed'
AND for_auction <> 1
I dont follow how i would put a SELECT GETDATE in that query.
Tony
For example, here is my actual query:
SELECT tblpayments.for_auction, tblpayments.txn_type, tblpayments.paymentdate, tblpayments.payment_id, tblpayments.mc_gross, tblpayments.mc_fee, tblitems.item_price, tblitems.item_name, tblcustomers.Cust_First, tblcustomers.Cust_Last
FROM (tblitems INNER JOIN tblpayments ON tblitems.txn_id = tblpayments.txn_id) LEFT JOIN tblcustomers ON tblpayments.customer_id = tblcustomers.Cust_ID
where paymentdate = #CreateODBCDate(now())#
AND payment_status = 'Completed'
AND for_auction <> 1
I dont follow how i would put a SELECT GETDATE in that query.
Tony
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Advisor
,
/t5/coldfusion-discussions/todays-date-in-ms-sql/m-p/477951#M43383
Jan 11, 2008
Jan 11, 2008
Copy link to clipboard
Copied
Bear in mind that in SQL Server the DATETIME datatype always
contains the time, you'll need to specify your WHERE clause to look
for datetime values starting at midnight today and ending prior to
midnight the next day.
I also recommend that you use cfqueryparam in your queries.
<cfset startDate="#DateFormat(Now(), 'mm/dd/yyyy')# 00:00:00" /> <!--- today at midnight --->
<cfset endDate="#DateFormat(DateAdd('d', 1, startDate), 'mm/dd/yyyy')# 00:00:00" /> <!--- the next day at midnight --->
SELECT mydata
FROM mytable
WHERE paymentdate >= <cfqueryparam value="#startDate#" cfsqltype="cf_sql_timestamp" />
AND paymentdate < <cfqueryparam value="#endDate#" cfsqltype="cf_sql_timestamp" />
I also recommend that you use cfqueryparam in your queries.
<cfset startDate="#DateFormat(Now(), 'mm/dd/yyyy')# 00:00:00" /> <!--- today at midnight --->
<cfset endDate="#DateFormat(DateAdd('d', 1, startDate), 'mm/dd/yyyy')# 00:00:00" /> <!--- the next day at midnight --->
SELECT mydata
FROM mytable
WHERE paymentdate >= <cfqueryparam value="#startDate#" cfsqltype="cf_sql_timestamp" />
AND paymentdate < <cfqueryparam value="#endDate#" cfsqltype="cf_sql_timestamp" />
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
TonyP
AUTHOR
New Here
,
LATEST
/t5/coldfusion-discussions/todays-date-in-ms-sql/m-p/477952#M43384
Jan 11, 2008
Jan 11, 2008
Copy link to clipboard
Copied
That worked perfect. Thank You!
It seems that i was trying to pull todays date with one var and instead for MS SQL you need to use a range as you said, like from midnight to midnight tonight.
Worked great. Thanks again.
It seems that i was trying to pull todays date with one var and instead for MS SQL you need to use a range as you said, like from midnight to midnight tonight.
Worked great. Thanks again.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

