Problems with dates in SQL
source link: https://www.codesd.com/item/problems-with-dates-in-sql.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Problems with dates in SQL
I'm writing a report that needs to collect data each day, between 0900hs and 1700hs. I thought it would be fine as follows:
cast(convert(char(8),t.trxtime,112)as time)
between CONVERT(VARCHAR(5),getdate(),108) >= '09:00'
and CONVERT(VARCHAR(5),getdate(),108) < '17:00'
....BUT no cigar.
Thank you!!!
Hmmm, you could just use datepart()
:
where datepart(hour, t.trxtime) between 9 and 16 and
cast(t.trxtime as date) = cast(getdate() as date)
I'm not sure if the date comparison is actually necessary.
Related Articles
Problem with date format using SSIS for Excel in SQL Server
sql server manager - problems with date
Problems with converting oracle.sql.TIMESTAMPTZ to string value
Problem with Trigger in SQL Server 2005
Problem with date comparison in Oracle
Problem with updating the SQL Server 2005 table variable
Request multiple min / max columns with date in SQL
NHibernate proxy causes problems with data binding
Dynamic Diagram of Sankey with Data from SQL Server 2012
Problem with date formats in JavaScript with different browsers
Problem with the reserved SQL keyword when you try to generate Spring Roo data on demand
Problem with data type Money in SQL SERVER vs string
Java problem with date
Problems with date and writing when exporting data to a text file in JAVA
Recommend
-
114
Find, convert and replace dates with Vim substitutions Find, convert and replace dates with Vim substitutions By Jeff Kreeftmeijer on 2017-10...
-
191
Explore PostsOptions Menu
-
159
quick copy and paste of a timestamp and will convert to your local timezone, UTC and another timezone of your selection
-
87
README.md ...
-
9
SQL Find historical sensor values at specific dates advertisements I have a database that has a vessel pressure that is trended every 30 sec...
-
11
Deleted JDBC dates in Java (java.sql package) advertisements I am working with JDBC and MySQL. I have a date column that I need included in my...
-
5
Format SQL Server Dates with FORMAT Function By: Daniel Calbimonte | Updated: 2021-06-09 |
-
5
Problems with SQL comparison and null values advertisements I have an update query that updates a field in one table when the value does not m...
-
4
Couple problems on SQL - 244 and 245 Back to General discussions forum
-
4
SQL-real-world-problems Introduction Before you get your first job with heavy SQL usage it is often difficult to understand what kind of queries you might end up writing. Is all I need joins and group by to be fluent in SQL?...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK