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

SELECT data grouped by WEEK in SQL

I have a working query (ORACLE SQL) that gives me gallons grouped by store number, with gallons summed by type and a percentage column as well. Each store number has a different conversion date from which I sum up the data - SELECT StoreNbr,…
BigRedEO
  • 807
  • 4
  • 13
  • 33
-1
votes
1 answer

SQL statement with 'DATEPART' and 'DATEADD' do not work. Are not recognized by server

Trying to pull client information from SQL server using PHP and count how many clients signed up last month based on the date they signed up. I want to use DATEPART and DATEADD to specify the parameters I want for grabbing last months information,…
Ken
  • 63
  • 13
-1
votes
3 answers

Join Multiple Select queries with where clauses for each

So I have a series of Amortization schedules, and I'd like to run a query to return the balances for the month of May on each schedule My query right now, looks something like this select ace.date, ace.balance, aacs.date, aacs.balance, axl.date,…
Danielle
  • 13
  • 4
-1
votes
1 answer

SQL Date - functions

>=DateAdd("ww",-9,Date()-Weekday(Date(),0)+1)) I have the above function in some SQL coding that I have inherited and am struggling to work out what it is actually calculating can anyone help?
T Steele
  • 1
  • 1
-1
votes
2 answers

Grouping by Week Datepart, display the spanning dates e.g. "25/12/2015 - 31/12/2015"

When using Datepart to group by week, is it possible to easily have it display the dates the weeks span. Below is an example of my sql: SELECT 'Week ' + cast(datepart(wk, Table.ApplicationDate) AS VARCHAR(2)) Week ,year(Table.ApplicationDate) Year…
Vereonix
  • 1,341
  • 5
  • 27
  • 54
-1
votes
1 answer

T-sql datediff doesn't look at the year if you pass in day for datepart?

I am using datediff in a query to return the dates that are less than 7 days from the start date. DECLARE @d1 DATE SET @d1 = (SELECT CurrentServiceWeek FROM Technician WHERE ID = 150) SELECT First_Name, Last_Name, Previous_Service_Date, …
Bmoe
  • 888
  • 1
  • 15
  • 37
-1
votes
5 answers

How to get a date part from a string in sql server

'UNK-JAN-2015' This is my date value. UNK refers Unknown value. Now I need to get only month from that. Is there any way to find it......
Jasper
  • 41
  • 2
  • 5
-1
votes
2 answers

Add 0 if day is lesser than 9 in sql

I have the following value: Jun **6** 2012 12:00:00:000AM What I want is: Jun **06** 2012 12:00:00:000AM 0 should only be prepended if the value of day is less than 9. How do I do this?
-1
votes
3 answers

How do I display dates in gridview column in format of mm/yyyy?

As far as I found on net the statement SELECT DATEPART(MONTH,columnName),DATEPART(YEAR,columnName) doing it and listing the result in 2 columns. What I need is do display date from database (MS SQL) in single column in format like mm/yyyy. Is there…
black12
  • 45
  • 2
  • 9
-2
votes
1 answer

how to get int by using Linq group by DATEPART month in C#

I have a StayDormApplications table , I have a SQL as below , var systemFilesItem = _db.StayDormApplications.Single(r => r.Id == dormapplication.Id); string SQL = "SELECT sum(days) days from StayDormApplications where poster = '" + LoginAccount +…
georgetovrea
  • 537
  • 1
  • 8
  • 28
-2
votes
3 answers

Get Previous Friday in SQL

How to get previous friday in SQL Server? Here is the code I have so far: select (7 -datePart(dw, getdate()+3)) +1
Bharath T
  • 41
  • 1
  • 7
-2
votes
1 answer

Total Orders and Total Revenue

I want total orders and total revenue on 31st dec. But in this query so many duplicate values are there.. select * from Orderdetails od inner join OrderProducts op on od.orderid=op.orderid inner join addonProducts ap on…
Myself
  • 13
  • 4
-3
votes
1 answer

Why SQL datepart(ww,GETDATE()) returns current week + 1

I am trying to get current week of the calendar. Let's assume today is 2022-03-14 12:00:00. I am using these 2: select GETDATE() // returns 2022-03-14 12:00:00 select datepart(ww,GETDATE() //returns 12 But as per calendar 2022-03-14 12:00:00 should…
Borislav Stefanov
  • 533
  • 3
  • 15
  • 38
-3
votes
3 answers

Calculating Age Using DoB from a Specific Date in the past

I am looking for some help with this: I need to calculate a members age (DoB field) as of 2/1/2020. For instance, if a member had a DoB of 2/18/91, I would want to see two fields. 1 for the actual age of the member as of today, and then the age of…
-3
votes
2 answers

What's the best way to split my results by day?

not sure where to go with this one. I know I need to split the date and time up from 'createdon' but then I'm stumped. I can bring back values with the query but I have to manually enter each day. `SELECT sum(CASE WHEN title LIKE '%Environmental%'…
1 2 3
17
18