Questions tagged [datepart]

DATEPART is a T-SQL function that converts a DATE type to INT according to provided format.

datepart(datepart,date_time_value) is a T-SQL function available in MS SQL Server and the SAP/Sybase family of database products.

SQL Server Syntax

SAP/Sybase Syntax

257 questions
0
votes
1 answer

SQL DatePart Week, year to reflect fiscal year

I currently have a report that uses DATEPART to return the week a 'car' was returned. However, the business I work for fiscal year starts first Sunday of the year (this instance commencing 03/01/2016 would be week 1). However, using SQL 'DATEPART…
PAPERCLIPSANDPAPER
  • 77
  • 1
  • 1
  • 10
0
votes
1 answer

SQL query with case datepart

I would like to get the data which will exclude weekends from result based on a bind variable value. Somehow I am not able to get this query to run. select * from tablename a WHERE a.date >= '2015-04-13' AND a.date <= '2015-04-21' AND CASE WHEN…
Rijoy
  • 11
0
votes
0 answers

Previous and Current Week Quantities JOIN Issue

This is my join this is where the issue is i know this to be true SELECT DR.DivNo ,p.[ProductCode] ,p.ProductClass ,p.EmpNo ,[Description] ,[CGNo] ,[SCGNo] ,dr.Retail ,bd.[Buying…
0
votes
1 answer

Update datetime timestamp minute value

Our data logger has recorded some non-processable data. The logger is logging 10 min mean values. Due to a bug of manufacturer device it has recorded some timestamps with jumping minute values like follows plantid …
veritaS
  • 511
  • 1
  • 5
  • 23
0
votes
1 answer

Converting MS Access query to T-SQL - datepart function

I am in the process of converting some MS Access queries into T-SQL (for use with SQL reporting services), and I've run into a problem. Turns out in MS Access queries, there is a function called DATEPART that has two optional parameters (parameters…
Scott
  • 123
  • 1
  • 1
  • 7
0
votes
3 answers

How do I check whether the input date's DAY is the last day of the given month in SQL?

DECLARE @Date DATE = '2/28/2014' I need to test whether the DAY in the DATE above is the LAST day of the month and it should work for all months in the year. If it's true, then I need to return a true, if not, then false. E.g. SET @Date =…
JJ.
  • 9,580
  • 37
  • 116
  • 189
0
votes
1 answer

How to extract date and time parts from mysql query

I need to select a max(date) from a MySQL table and have each part of the date and time be in a separate variable. Something like: select max(date) as year, month, day, hour, minute, second from table How would I do that?
Xi Vix
  • 1,381
  • 6
  • 24
  • 43
0
votes
1 answer

Why do I get different results with this SQL Date Part and date parameters

When I run this where clause on my table I get 2 different results and to me its seems like I should get the same number of records back. The one I'm using just a static date to test and the other should also retrieve the same results where I'm…
Etienne
  • 179
  • 3
  • 12
0
votes
1 answer

How to concatenate datepart results?

I have a column called "Total" which holds values such as "1899-12-30 07:56:00.000" and "1899-12-30 03:52:00.000". Let this two be our examples. I need to add the hour values in rows together (i.e 07:56 + 03:52 = 11:48) to create another column.…
Ege Bayrak
  • 1,139
  • 3
  • 20
  • 49
0
votes
1 answer

Querying the exact years in between two other dates (MS SQL)

I am struggling with an assignment and I am not sure if there is a solution. To be clear: I am not looking for the amount of years in between(datediff()). I have to join two tables: Table 1 with attributes: ID P_Startyear P_Endyear Table 2 with…
JeroenvS
  • 5
  • 3
0
votes
0 answers

EF: Where(Date.Month == m) versus Where(Date >= ... && Date <= ...)

I have a table, Measurements, which has a Date column. This column is indexed (is a non unique index though) Using EntityFramework I want to get all items from a certain month and year. Question: What alternative is better in terms of…
sports
  • 7,851
  • 14
  • 72
  • 129
0
votes
1 answer

Exclude Day of Week

I'm trying to exlcude Thursdays from a date range in SQL Server The following is what I came up with from other examples: SELECT * FROM table WHERE ((DATEPART(WEEKDAY, date_field) + @@DATEFIRST) % 7) NOT IN (5) This appears to be working but I…
boognish
  • 50
  • 8
0
votes
1 answer

Calculate year week number from given period in VBScript

Scenario: Trying to find out the End Week Number(current year's week number) and Start Week Number using a given period. Suppose PeriodWeeks = 10. That means from today's week number to last 10 weeks which surely will go to last year in current…
PineCone
  • 2,193
  • 12
  • 37
  • 78
0
votes
1 answer

Using DATEPART in sql statement to get records with specific year

In Classic ASP: I can extract the year from a date/time field: tester=rs.fields("datestamp") tester=DATEPART("yyyy",tester) But I cannot seem to figure out how to make this work in a SQL statement to bring all the records from a specific…
0
votes
1 answer

How to return a value greater than 23:59:59 in a date and time column

I don’t know if this is possible but I am trying to return contracted hours from our rota system using the select statement below to return just the Hours and minutes from a date and time column. However, it only returns values accurately up to…
Jason Shaw
  • 33
  • 6