datepart

SQL Server: convert to today then add 8 hours

对着背影说爱祢 提交于 2020-01-05 07:13:14
问题 nextUpdate can be any date time value in the past. I'm trying to update the nextUpdate field to today's date but keeping the time unchanged and then add 8 hours. I get error converting string to datetime T-SQLe: UPDATE business.dbo.db_schedule SET nextUpdate = DATEADD(hh, 8, CONVERT(datetime, CONVERT(VARCHAR(8), GETDATE(), 111) + ' ' + CONVERT(VARCHAR(8), nextUpdate, 108), 111)) WHERE sno = 8 datetime format in my location is 111 回答1: UPDATE business.dbo.db_schedule SET nextUpdate= DATEADD(hh

Convert Military Time to Standard Time Error

风流意气都作罢 提交于 2019-12-24 18:53:23
问题 I have a data set that pulls back visit time in hour/min format (e.g. - 12:33PM would be 1233). I am trying to use the DATEPART function but it keeps giving me a syntax error stating that : "expecting something between '(' and the 'HOUR' keyword. The section below is the piece of the SQL that is giving me errors: CASE WHEN DATEPART(HOUR , VSL.VISIT_TIME) > 12 THEN DATEPART (HOUR, VSL.VISIT_TIME) -12 ELSE DATEPART (HOUR, VSL.VISIT_TIME) END AS THE_TIME I am trying to just get the hour part of

How to convert a DATEPART hour that's military time for midnight (00) to a value I can use when I need it for a calculation?

∥☆過路亽.° 提交于 2019-12-24 06:59:08
问题 I have this code which I'm writing into a stored procedure: declare @StartTime time declare @EndTime time declare @Temp_StartTime time declare @temp_StartHour int declare @temp_EndHour int declare @temp_StartMinute int declare @temp_EndMinute int SET @StartTime='22:30:00' SET @EndTime='00:52:00' SET @Temp_StartTime=@StartTime SET @temp_StartHour=DATEPART(HOUR, @StartTime) SET @temp_EndHour=DATEPART(HOUR, @EndTime) SET @temp_StartMinute=DATEPART(MI, @StartTime) SET @temp_EndMinute=DATEPART(MI,

How do you convert the number you get from datepart to the name of the day?

怎甘沉沦 提交于 2019-12-22 04:57:13
问题 Is there a quick one-liner to call datepart in Sql Server and get back the name of the day instead of just the number? select datepart(dw, getdate()); This will return 1-7, with Sunday being 1. I would like 'Sunday' instead of 1. 回答1: select datename(weekday, getdate()); 回答2: It actually took me more searching than I thought it would to find this answer. It's funny how you can use a technology for ages and never know about simple functions like this. select datename(dw, getdate()) I'm not

Select records from start of month to current date

↘锁芯ラ 提交于 2019-12-20 04:36:44
问题 I'm trying to select records that were added to the database between the start of the current month and the current day - I more or less know how to get records from the current day, and within a specific time period - but how do I get it so it starts from the beginning of the current calendar month? 回答1: DECLARE @sm DATETIME; SET @sm = DATEADD(DAY, 1-DAY(GETDATE()), DATEDIFF(DAY, 0, GETDATE())); SELECT columns FROM dbo.foo WHERE datetime_column >= @sm; 回答2: WHERE YEAR([Date])=YEAR(GETDATE())

How to properly convert a date into a ISO-8601 Week number format in SQL Server?

a 夏天 提交于 2019-12-20 03:03:22
问题 ISO-8601 states that week numbers are to be formated as YYYY-W## - observe that the week number should be two digits as 01, 02, ... SELECT cast(DATEPART(YYYY, CreationDate) as varchar) + '-W' + cast(DATEPART(ISO_WEEK, GETDATE())` The problem is that this gives the week number as 1, 2, ... What is the correct way of extracting 2020-W01, ... 回答1: SELECT cast(DATEPART(YYYY, CreationDate) as varchar) + '-W' + Right('0'+cast(DATEPART(ISO_WEEK,CreationDate) as Varchar),2) 回答2: The original question

Extract weekday, millisecond, microsecond, nanosecond from a date in Postgres

為{幸葍}努か 提交于 2019-12-12 03:55:07
问题 How to extract the millisecond, weekday, microsecond, nanosecond from a date in Postgres. I have tried the extract methods too, but I could not find an exact equivalent. 回答1: I'm not sure what equivalent are you looking for, but: there is no nanosecond precision in PostgreSQL: The allowed range of p (precision) is from 0 to 6 for the timestamp and interval types. some date parts include others: i.e. milliseconds contains seconds & microseconds contains milliseconds (and thus seconds too). If

SQL Server CE: SET DATEFIRST not working

馋奶兔 提交于 2019-12-11 13:57:13
问题 I'm using SQL Server CE for rapid application development purposes and have hit a little snag - it doesn't seem to support changing the start day of the week. What I've tried: SET DATEFIRST 1; which yields: Unrecognized SET statement as a response (both via a query window and through code). I've googled around and can't find anything in the documentation as to whether changing the start date of a week is supported or isn't supported by SQL Server Ce, nor can I find any alternative method of

Copy prior month value and insert into new row

谁说胖子不能爱 提交于 2019-12-11 03:56:50
问题 Here is an example of the current table I have: 1) Table name: TotalSales Name Year Month Sales ------ ---- ----- ----- Alfred 2011 1 100 What I want to do is create a table like this, add a new row(Prior month sales): 2) Table name: TotalSales Name Year Month Sales Prior month sales ------ ---- ----- ----- ----------------- Alfred 2011 2 110 100 Not sure how to this, but this is what I have been working on: SELECT Name, Year, Month, Sales, Sales as [Prior Month sales] FROM TotalSales WHERE

Time difference between dateTime fields SSRS

不想你离开。 提交于 2019-12-10 16:12:31
问题 I have two datetime fields and I need to show the difference between them. I've used this expression to calculate it: =DateDiff("n", Fields!hra_atncion.Value, Fields!fcha_incio.Value) The result column should be on HH:mm , but the result is a Long expression type. Something like 428011156 Any answer will be apreciated! UPDATE 21/11/2013 How I obtain the time difference in minutes between 12-11-2013 20:00 and 14-11-2013 08:00 ? 回答1: I think, you should try this expression: =Datediff("h",Fields