I can get the whole of yesterday and today using this query -
SELECT site, ord_date,
-
LEFT(RTRIM(LTRIM(descr)),24) account
-
FROM orders
-
WHERE ord_date BETWEEN
-
CAST(CAST(DATEADD(DAY,-1,GETDATE()) AS INT) AS DATETIME)
-
AND
-
CAST(GETDATE() AS DATETIME)
Casting GETDATE to INT truncates the time element and casting back to DATETIME resets the time element to midnight.
I figured if I did something like this it would give me 17:00 yesterday - CAST(CAST(DATEADD(DAY,-1,GETDATE()) AS INT)+' 17:00:00.000' AS DATETIME)
But error:
Syntax error converting the varchar value ' 17:00:00.000' to a column of data type int.
I must be close.
Any help appreciated
5 7362
Here, read some of this...
Happy Coding!!!
~ CK
Here, read some of this
That doesn't teach me anything.
String literals are used for the dates throughout.
Or did I miss something?
Please try this.
DATEADD( HH, 17, CAST(CAST(DATEADD(DAY,-1,GETDATE()) AS INT) AS DATETIME))
-bala
- DATEADD( HH, 17, CAST(CAST(DATEADD(DAY,-1,GETDATE()) AS INT) AS DATETIME))
-
Good Thinking! Add 17 hours to midnight. Wow. I'll try that. Thanks.
Just an update for anybody interested.
CAST ...TO INT is unreliable.
It can flip a day either way, probably something to do with rounding.
CONVERT to a date works better. then CAST back to DATETIME to get midnight.
And simply DATEADD any number of hours you like - DATEADD(HH,17,CAST(CONVERT(VARCHAR,DATEADD(
-
DAY,-1,GETDATE()) ,23) AS DATETIME)) yesterday1700
Sign in to post your reply or Sign up for a free account.
Similar topics
by: dregier |
last post by:
attached is my full query that I am currently working on:
Declare @counterday1 int
Declare @counterday2 int
set @counterday1 = '20'
set @counterday2 = '629'
Declare @CounterMin07_01 float...
|
by: Fred |
last post by:
I am trying to get al the rows from table1 where datetime is between 9:00AM
yesterday and 9:00AM today if the time now is less than 9:00AM. Otherwise it
should return all where datetime>9:00 AM...
|
by: PYCTAM |
last post by:
Hi,
I have data stored as in below sample :
-------------------------------+---------------------------------+--------------
DateBegin | DateEnd | Rate...
|
by: elubin_nospam |
last post by:
Given these two tables in DB/2:
Date Activity
------------------- --------
2005-01-02 00:00:00 1
2005-01-05 00:00:00 2
2005-01-05 00:00:01 1
2005-01-07 00:00:00 2...
|
by: MLH |
last post by:
I have a table (tblCorrespondence) holding records with fields like
, , , , , ,
, etc...
About a dozen 's are defined and I often use queries to
extract records of a given . That's pretty easy....
|
by: Maya |
last post by:
Hello guys,
I have table "Shopping" that has 3 columns (Item, Category, Price)
Is there a straight forward way in T-SQL to select the Item that has
the highest price for each category as below:...
|
by: Mahesh S |
last post by:
Hi
I would like to write a SQL select statement that would fetch rows
numbered 50 to 100.
Let me clarify, if i say "fetch first 10 rows only", it returns the
first 10 rows from the resultset....
|
by: KingKong07 |
last post by:
Hi
I have a table with the columns
Id, Date, Downtime, FromDate, ToDate
How the data should look like in the table
33 2007-04-17 00:00:00.000 2 2007-04-17 15:55:52.000 2007-04-17...
|
by: jerry101 |
last post by:
hi,
i've got a form in which the user can fill out consisting of 2 text boxes to enter information in, a drop down box of choices and of course a submit button. when they fill it out, it sends the...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |