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
3
votes
1 answer

DATE_PART and Postgresql

I have a problem when I subtract two date in a function DATE_PART in this query. SELECT TO_CHAR(date_trunc('month',sql_activity_days.created_month),'YYYY-MM') AS "sql_activity_days.created_month", coalesce(SUM( CASE …
Julie Levesque
  • 115
  • 3
  • 3
  • 11
3
votes
2 answers

T-SQL Calculate recurrences of a Date

I am working on a CTE which calculate the recurrences of a Week but I am having some problems when the pattern cross the year. The CTE should Calculate all occurrences based on the following parameters: Recurrence Count - how many times it will…
Raffaeu
  • 6,694
  • 13
  • 68
  • 110
3
votes
3 answers

Insert into MySQL table all Sundays and Saturdays from current year

I have this tiny table with just "fecha" field in it. I need a MySQL query that inserts every sunday and saturday of the year to the table. My own research got me to the point where i know i need to do something like this: DECLARE diaRecorrido…
GonHL
  • 67
  • 8
3
votes
2 answers

Datepart Week Sql (With 53 weeks for year)

I'm calculating the week for a specific date in SQL for example '2016-01-20' (yyyy-mm-dd) but SQL returns week: 4, and that is wrong because this year the first week started on '2016-01-04' the result must be week: 3. I think the issue is generatad…
Sebastian Pelaez
  • 126
  • 2
  • 12
3
votes
3 answers

How to get Quarter from a date in Firebird SQL

I can easily get total sales in this month and previous month. SELECT ‘This Mount’, SUM(Price) FROM Sales WHERE EXTRACT(MONTH FROM OrderDate) = EXTRACT(MONTH FROM CURRENT_DATE) AND EXTRACT(YEAR FROM OrderDate) = EXTRACT(YEAR FROM…
Zebedee
  • 420
  • 2
  • 7
  • 19
3
votes
1 answer

Is it possible in Microsoft SQL Server to create a column that is a datepart?

I want to create a column that would be something like this: create table dbo.t1 ( [Notification_Month] datepart(mm, [date]) null, ) I want to store the month as a date property without storing other parts of the date. It's a weird question I…
user3486773
  • 1,174
  • 3
  • 25
  • 50
3
votes
3 answers

Error: DATEPART does not exist, frp, SQL to select last months records

I'm trying to get an SQL query to select all records from last month, I have this which from looking numerous places is exactly what I should need, and should work: SELECT * FROM orders WHERE DATEPART(yy,DateOrdered) =…
Vereonix
  • 1,341
  • 5
  • 27
  • 54
3
votes
5 answers

TSQL Filtering a query by time / hours

Ok, I'm running query builder out of visual studio 2008. I'm trying to filter the results of the query by time; that is, I want to pull everything from the start of yesterday to noon yesterday. I've been using GETDATE()-1 for yesterday, which pulls…
nbpeth
  • 2,967
  • 4
  • 24
  • 34
3
votes
1 answer

SQL Count No of Mondays tuesdays etc from year

I want to create a table which will show me a count of every weeks day for the current year by months as shown in the table below. I know i need to use a with statement but have not managed to crack it just yet. I am using MS SQL Server 2008 r2 and…
user2040295
  • 107
  • 1
  • 9
3
votes
5 answers

Select Where Month= X and Year= Y

I have the following select: SELECT * FROM Table WHERE Column= datepart(month,'2013-05-07 10:18:00') AND Column= datepart(year,'2013-05-07 10:18:00') I want it to show me itens where month= 05 and year= 2013. Actually it isn't showing anything…
Khrys
  • 2,670
  • 9
  • 49
  • 82
3
votes
1 answer

How to Group By Week Across Year Boundary in TSQL

I use tsql to sum weekly data (starting date is Monday). Last week spanned across the boundary of 2012 and 2013, which means that I get two weekly sums. Is there a way to group the data within tsql so I get one weekly sum for 2012-12-31 to…
Adolph Trudeau
  • 351
  • 1
  • 8
3
votes
2 answers

Need To Pull Data With Specific Date Range From Current Day In Sql Express 2008

On my table I have a "Datemodified" column. I was to be able to pull results based on that Column. I want to be able to pull anything from 6am to 6pm. This query needs to be able to be used everyday, so the ways I've seen, use a specific date and…
user1800374
  • 75
  • 1
  • 8
3
votes
3 answers

SQL change format of Datepart Month

How do you change the DATEPART format of the month to include the 0 in front of the month? For instance 5 should be 05. What I have tried, but none of it works, (only gives me 5) Createdate = 2008-07-25 13:43:48.000 CONVERT(varchar(2),…
Ruan
  • 3,969
  • 10
  • 60
  • 87
3
votes
2 answers

convert week datepart number to date within week (week of...)

I am trying to figure out how to convert a datepart for a week to the Monday of that week. I am using this: datepart(ww, DateCompleted) as week to group a set of orders in our system by week. My goal is for this to say instead of 37, i want…
wondergoat77
  • 1,765
  • 9
  • 32
  • 60
2
votes
2 answers

SQL - Summing events by date (5 days at a time)

What I'm trying to do is calculate the number of call center events for a sliding 5 day period for a given range of data; if the event count exceeds (for example) 10, I need to alert the managers. I've already created the data set which contains…
Andy Evans
  • 6,997
  • 18
  • 72
  • 118
1
2
3
17 18