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
0 answers

Arithmetic overflow error converting expression to data type datetime-in stored procedure

I've ready as many answers to this problem as I could, but cannot come up with the solution. We recently moved our application from SQL 2008 to 2012. This worked without a problem in 2008. I'm only going to add parts of the SP where I think the…
0
votes
1 answer

SQL - Determine last day of previous week with flexibility

I'm trying to create a flexible way to determine the last day of the previous week, knowing that this will be run in different environments that have different planning weeks (some customers use Sat-fri; Sun-Sat; Mon-Sun). I was planning on creating…
NRud
  • 13
  • 2
0
votes
4 answers

Datepart function in SQL query not working with OLEDB connection in VB.NET

I am trying to fetch Date, Month and Year separately from date column in Access Database. I am using following code for it. I don't know what is the problem with this, but either it shows me error or no data is returned. I am new to OLEDB so I don't…
user3762349
  • 1
  • 1
  • 4
0
votes
1 answer

Get Number of Weeks that have passed from a certain date to today SQL

Im trying to design a table with a column that has the total number of weeks that have passed from a static, hardcoded date, until today. For example, if the today is June 27, 2014, I want to find how many weeks have passed since May 31st, 2012; the…
jFram
  • 73
  • 3
  • 14
0
votes
1 answer

SqlFunctions convert string to date

I'm working on a project and i have problem with filtering records by date. I have a generic method to search the records of any entities,my searchQuery is like '2014-03-15' and the records datetime format is '2014-03-15 00:00:00.000', My sql query…
0
votes
1 answer

tsql group by months with dateadd()

I'm grouping data with dateadd() by weeks, but I want to group by months instead. I've got this fun little dateadd function. DATEADD(day, - (1 * DATEPART(dw, Orders.OrderDate - 1)) + 1, CONVERT (date, Orders.OrderDate, 103)) so we're subtracting…
nbpeth
  • 2,967
  • 4
  • 24
  • 34
0
votes
2 answers

Ordering a monthly and quarterly query

I want to start off by giving a tremendous thanks to everyone who participates in this forum. The plethora of knowledge and examples has been an amazing resource at 3 am the day before [INSERT PROJECT NAME HERE] was due and I arrived at a…
0
votes
2 answers

sql server 2012 - ranking orders by year, month, supplier and location

I have a table containing the following. pickup_date, Supplier_id, Location pickup_date is a datetime, and supplier id is a number. Location is a string. I would like to output a list ordered using the two datepart fields below (to match other…
finngeraghty
  • 107
  • 1
  • 8
0
votes
2 answers

SQL DATEPART without creating a new column

I wish to be able to be able to do something like this for use with @YearVar later. SET @YearVar DATETIME = CONVERT(nvarchar, date_hired, 106), DATEPART(YEAR, date_hired) However the only way I know how to datepart is like this : SELECT…
Andy
  • 373
  • 1
  • 7
  • 24
0
votes
1 answer

how to do a sum iff expression for datepart m in last month

I am trying to write an expression to count the number of requests within a specific month from a year's worth of data. I have tried: =sum(iif((datepart("M",Fields!RequestDate.Value)) = (datepart("m",Now(-1))),1,0)) and many more different…
grahamie
  • 301
  • 2
  • 6
  • 15
0
votes
4 answers

SQL Find Count of Records by Day and By User

I am trying to find the count of days listed by person where they have over 100 records in the recordings table. It is having a problem with the having clause, but I am not sure how else to distinguish the counts by person. There is also a problem…
Klay
  • 183
  • 5
  • 12
0
votes
2 answers

get year from Date Excel cell value not working

I have the following code: For rowIndex = rowOffset To 15 Dim currentDate As Date Dim nextRowDate As Date currentDate = Cells(rowOffset, colIndex).Value nextRowDate = Cells(rowIndex + 1, colIndex).Value Dim…
Jimmyt1988
  • 20,466
  • 41
  • 133
  • 233
0
votes
1 answer

Need to sort by Date then Hour, then output Date, text Day of week , range of hours SQL Server 2008 R2

NEWBIE at work! I am trying to create a simple summary that counts the number of customer visits and groups by 1) date and 2) hour, BUT outputs this: Date Day of Wk Hour #visits 8/12/2013 Monday 0 5 8/12/2013 …
0
votes
1 answer

Date format with zeros

With this: , CAST(DATEPART(Yy,DATEADD(Month,1,GETDATE())) as varchar(4)) + '-' + CAST(DATEPART(Mm,DATEADD(Month,1,GETDATE())) as varchar(2)) + '-' + CAST(DATEPART(Dd,DATEADD(Month,1,GETDATE())) AS varchar(2)) AS expiration_date I get this:…
user2646056
  • 41
  • 1
  • 1
  • 5
0
votes
1 answer

Format a date time string

Im having a problem formatting a datetime field in ASP Classic. The format I need is yyyy-mm-dd hh:mm:ss this is my code so far: changeToDate = cdate(Request.Form("datepicker")&" "&Request.Form("timepicker")) dateTime = DatePart("d",…
user2255811
  • 496
  • 2
  • 8
  • 19