code green 1,726
Recognized Expert Top Contributor
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 7399 ck9663 2,878
Recognized Expert Specialist
Here, read some of this...
Happy Coding!!!
~ CK
code green 1,726
Recognized Expert Top Contributor
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(DATEA DD(DAY,-1,GETDATE()) AS INT) AS DATETIME))
-bala
code green 1,726
Recognized Expert Top Contributor - 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.
code green 1,726
Recognized Expert Top Contributor
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
Declare @CounterMin08_01 float
Declare @CounterMin09_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 today.
Is this possible as a query in sql2000?
|
by: PYCTAM |
last post by:
Hi,
I have data stored as in below sample :
-------------------------------+---------------------------------+--------------
DateBegin | DateEnd | Rate
-------------------------------+---------------------------------+--------------
2005-11-13 00:00:00 2005-11-14 00:00:00 63.0000
2005-11-14 00:00:00 2005-11-15 00:00:00 63.0000
2005-11-15 00:00:00 2005-11-16 00:00:00 45.0000
|
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
2005-01-17 00:00:00 2
2005-02-02 00:00:00 1
2005-02-03 00:00:00 1
|
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.
But, recently, I wanted to list all "15" letters, a few of
the above mentioned fields and one additional field: of
nother letter "00" in the same row. That's the tough part.
| |
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:
Item Category Price
-------- ----------- ----------
1 2 13.99
2 2 20.69
|
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. how do I get a specific subset of
rows from the result set if I give a start and end value. For example,
retreiving rows 50 to 100 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 15:58:17.000
34 2007-04-17 00:00:00.000 68 2007-04-17 15:58:17.000 2007-04-17 17:06:27.000
35 2007-04-17 00:00:00.000 1 2007-04-17 17:06:27.000 2007-04-17 17:06:37.000
|
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 email of information to me fine. everything comes through apart from the option they've chosen from the drop down box.
the code i have is the following;
<form action="mail.php" method="post">
<input onfocus="this.select()" name="name"...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |