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

Nhibernate select datepart

I need to use this SQL string in different database context, I know it work in MSSQLCE4 but it won't work in MySql sql = session.CreateSQLQuery( "SELECT DISTINCT DATEPART(yyyy," + DataRicezioneFile + ") AS Data" + " FROM " + Ricevuta + …
Shyguy
  • 77
  • 8
0
votes
1 answer

Counting records twice

I need to have 2 columns for a result. 1 source table/view has the field called "Date_Entered" which is yyyy-mm-dd hh.mm.ss for each entry (full date/time stamp) I need a query that builds 2 columns of results. The results are the total number of…
Coogrrr
  • 3
  • 2
0
votes
3 answers

DatePart in asp.net

How do I get the values of days (Sunday to Saturday) using DatePart in .NET? My idea is, if it is a Saturday or Sunday, I have to skip the loop.
MusicLovingIndianGirl
  • 5,909
  • 9
  • 34
  • 65
0
votes
1 answer

Date/time conversion error with DATEPART()

I am getting an error when I try to use the datepart function in a where clause. Can someone please have a look at my syntax below and offer some…
Flashgordan
  • 63
  • 1
  • 1
  • 10
0
votes
1 answer

Determine DATEPART by int value in SQL

OK, so I am doing a software tool that alerts CRB's that are going to expire. The expiry intervals are determined by the user of the program. I am currently using SQL Server 2008. So I am trying to do an SQL statement that will retrieve all records…
Weebie
  • 230
  • 1
  • 14
0
votes
2 answers

Sort by minute doesn't work

I'm trying to sort my photos by hour and minute but it will not catch the minutes - it's just keep saying that nothing exists for that hour and minute. If I'm trying to sort only after the hours, it works perfectly. I have tested WHERE…
Airikr
  • 6,258
  • 15
  • 59
  • 110
0
votes
1 answer

Using DATEPART function in access SQL query with joined tables and aggregate function

I want to select the year and quarter parts of the date in a table rather than the whole date. I built the following query to achieve this: SELECT Clients.ClientID, Sum(AccountVals.ValuationAmount) AS SumOfValuationAmount, …
harryg
  • 23,311
  • 45
  • 125
  • 198
0
votes
2 answers

Update with Datepart a table

Hi i have one table in sql server and i have added one bit for each week day. I have one property that's a date and i want to update all the table updating the bit depending of the dayofWeek of this date. I have read something about t-sql (datepart)…
bombai
  • 927
  • 1
  • 17
  • 27
0
votes
1 answer

Filtering data based on a top row

I have a set of period something like PERIODID PERIODSTART PERIODEND PRICE STARTDOW 1 2012-12-01 2012-12-10 10 6 2 2012-12-11 2012-12-20 20 -1 3 2012-12-21 2012-12-30 30 -1 Meaning that reservation in period 1…
mko
  • 6,638
  • 12
  • 67
  • 118
0
votes
1 answer

Datepart week function wont work Please need assistance

The table I am trying to use is create type Rehearsal_ty as object (RehID char(4), RLocation add_ty, Attendance varchar2 (100), RDate date) create table Rehearsal_tbl of Rehearsal_ty The select statement I am trying to use can't get it to work…
TomC
  • 1
  • 1
  • 1
0
votes
2 answers

Using DATEPART for AM works correctly but does not work for PM query

I'm using a query to pull a report for our 3rd shift folks. The issue I just noticed when the report was mailed with 0 results is that I have it set right now to run from 6pm to 5:59am the next morning. Since I have the date field = the GETDATE,…
user1800374
  • 75
  • 1
  • 8
0
votes
3 answers

copy first cell to second then add hours as int (DATEPART)

I have data in the table like the following. TimeIn TimeOut ------------------------------------- 6/1/2010 09:00:00 Null 6/2/2010 09:00:00 6/2/2010 16:45:00 6/3/2010 10:05:00 Null …
LoneXcoder
  • 2,121
  • 6
  • 38
  • 76
0
votes
1 answer

Using a DatePart inside a switch case statement

I'm a beginner to SQL making a stored procedure with the goal of taking a specified time range and interval, and returning data within that time range grouped by the interval. For example, an input of a two week time range and 2 day interval will…
disambiguator
  • 318
  • 1
  • 2
  • 14
-1
votes
3 answers

How to subtract next row from first one for each account id in SQL?

The question I am trying to answer is how can I return the correct order and sequence of weeks for each ID? For example, while it is true the first week for each ID will always start at 1 (its the first week in the series), it could be the following…
Gabe Verzino
  • 346
  • 1
  • 10
-1
votes
1 answer

Calculation using timestamp

I have a table containing webpage 'hits' and timestamps associated daily cumulative hits. Using a 24-hour clock, I want to calculate the "grossed up" hits. For example: hits of 10,000 for 2020-07-13 10:10 is 10,000 hits for 10 hours and 10…
Coding_Newbie
  • 365
  • 1
  • 3
  • 11