dateadd

Convert specific BigInt to DateTime in T-SQL

99封情书 提交于 2019-12-10 07:31:03
问题 I have bigInt: 635307578922100000 which I need to convert to DateTime . I've tried few ways to do this: SELECT DATEADD(S, CONVERT(bigint,635307578922100000) / 1000, CONVERT(DATETIME, '1-1-1970 00:00:00')) and: SELECT DATEADD(ms, 635307578922100000 / 86400000, (635307578922100000 / 86400000) +25567) While I found the codes above work with bigInts like: 1283174502729 , with my bigInt I get the following error: Msg 8115 ... Arithmetic overflow error converting expression to data type datetime.

addition of date in sql function

£可爱£侵袭症+ 提交于 2019-12-08 09:50:28
问题 I have a query in sql which i wrote in C#.what the query do is, calculating something like if i have an input of two columns date and no. of balls as Date No. of balls 21/11/2013 2 22/11/2013 3 23/11/2013 4 24/11/2013 5 25/11/2013 2 26/11/2013 5 27/11/2013 4 28/11/2013 3 29/11/2013 9 30/11/2013 8 01/12/2013 7 02/12/2013 4 03/12/2013 5 04/12/2013 6 05/12/2013 2 06/12/2013 0 07/12/2013 1 the output should be look like newdate no. of balls 21/11/2013 -27/11/2013 25 28/11/2013-04/12/2013 42 05/12

How to generate date in SQL Query?

孤街醉人 提交于 2019-12-08 08:43:27
I want to generate date value since 1/1/2011 - 31/12/2011 on sql query. Example My Table A Field A Field B Field C 1 01/01/2011 125 2 03/01/2011 100 3 05/01/2011 50 I want to result : Field A Field B Field C 1 01/01/2011 125 0 02/01/2011 0 2 03/01/2011 100 0 04/01/2011 0 3 05/01/2011 50 ... 0 31/12/2011 0 Please Advice Me and Thank a lot. Under SQL Server, you can create a table-valued function rather than creating a temporary table, as this is reusable between queries: -- List all of the dates between startdate and enddate (inclusive) CREATE FUNCTION [dbo].[DatesBetween] ( @startdate date,

How to generate date in SQL Query?

 ̄綄美尐妖づ 提交于 2019-12-08 08:39:03
问题 I want to generate date value since 1/1/2011 - 31/12/2011 on sql query. Example My Table A Field A Field B Field C 1 01/01/2011 125 2 03/01/2011 100 3 05/01/2011 50 I want to result : Field A Field B Field C 1 01/01/2011 125 0 02/01/2011 0 2 03/01/2011 100 0 04/01/2011 0 3 05/01/2011 50 ... 0 31/12/2011 0 Please Advice Me and Thank a lot. 回答1: Under SQL Server, you can create a table-valued function rather than creating a temporary table, as this is reusable between queries: -- List all of

Adding one year to a date field in postgresql

半腔热情 提交于 2019-12-06 17:09:19
问题 I have a table in postgresql with a field_date using the syntax 'YYYY-MM-DD', I want to add a year to the field with the the sentence: UPDATE table SET date_field = DATEADD(YEAR, 1, date_field); but postgres return: ERROR: column "year" does not exist I can't see what's wrong with the sentence 回答1: Try this: UPDATE table SET date_field = date_field + interval '1 year' It appears that you were trying to use SQL Server's DATEADD() function, which does not exist in Postgres. 来源: https:/

如何计算本年度的每个月有多少天?

烈酒焚心 提交于 2019-12-06 05:03:06
DECLARE @dbegin DATE = DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()), 0); --获取本年第一天 DECLARE @dend DATE = DATEADD(DAY, -1, DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 1, 0)); --本年最后一天 WITH ctea (ddate) AS (SELECT @dbegin AS ddate UNION ALL SELECT DATEADD(DAY, 1, ddate) FROM ctea WHERE ddate < @dend) SELECT MONTH(ddate) AS imonth, COUNT(*) AS idays FROM ctea GROUP BY MONTH(ddate) OPTION (MAXRECURSION 0); 如何计算本年度的每个月有多少天? 来源: https://www.cnblogs.com/felix22/p/11963198.html

select the same day each month for the next 5 years using SQL?

匿名 (未验证) 提交于 2019-12-03 08:56:10
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: How do i select the same day each month for the next 5 years using SQL? eg: 05 Jan 2013 05 Feb 2013 05 Mar 2013 I have tried: select dateadd ( day ,- day ( dateadd ( month , 1 , current_timestamp )) , dateadd ( month , 1 , current_timestamp ) ) 回答1: How about something like DECLARE @StartDate DATETIME = '05 Jan 2013' , @YearsAdded INT = 5 ; WITH Dates AS ( SELECT @StartDate [ Date ] UNION ALL SELECT DATEADD ( MONTH , 1 ,[ Date ]) FROM Dates WHERE DATEADD ( MONTH , 1 ,[ Date ]) <= DATEADD ( YEAR , @YearsAdded , @StartDate ) ) SELECT

sql server Dateadd()函数

匿名 (未验证) 提交于 2019-12-02 23:47:01
sql文档: https://docs.microsoft.com/zh-cn/sql/t-sql/functions/dateadd-transact-sql?view=sql-server-2017 语法:DATEADD (datepart , number , date ) 参数说明: 1.datepart: https://docs.microsoft.com/zh-cn/sql/t-sql/functions/dateadd-transact-sql?view=sql-server-2017 https://www.cnblogs.com/vip7758458/p/8134582.html https://www.cnblogs.com/shamo89/p/9489603.html https://www.cnblogs.com/xingyadian/p/9056269.html 2.number: 3.date:

SQL查询最近三个月的数据(查询最近几天,几年等等)

▼魔方 西西 提交于 2019-12-01 18:10:03
select DateAdd(Month,-3,getdate()) --返回一个时间,根据这个时间点去查询想要的数据即可 --DateAdd函数的详细说明: --DateAdd(interval, number, date) --interval 必选。字符串表达式,表示要添加的时间间隔。 --yyyy 年 --q 季度 --m 月 --y 一年的日数 --d 日 --w 一周的日数 --ww 周 --h 小时 --n 分钟 --s 秒 --number 必选,数值表达式。 --表示要添加的时间间隔的个数。数值表达式可以是正数(得到未来的日期)或负数(得到过去的日期)。 --date 必选。标识查询时的对比时间,getdate()在SQL中说明是现在的时间 。 --例子: Select DateAdd(Month,-3,getdate()) --以当前时间为准,返回三个月之前的一个时间点 Select DateAdd(yyyy,-3,getdate()) --以当前时间为准,返回三年之前的一个时间点 Select DateAdd(Month,3,getdate()) --以当前时间为准,返回三个月之后的一个时间点 来源: CSDN 作者: 炊烟渺渺 链接: https://blog.csdn.net/wy965874100/article/details/78718370

DATEADD equivalent in PostgreSQL [duplicate]

血红的双手。 提交于 2019-12-01 14:54:02
问题 This question already has answers here : Postgres INTERVAL using value from table (3 answers) Closed 5 years ago . Is there an equivalent to this T-SQL command in PostgreSQL? select dateadd(hh,duration_in_hours,start_date) as end_date I have found only interval keyword with subsequent string, but this terrible construction returns syntax error: select start_date + interval cast(duration_in_hours as varchar) || ' hours' It allows only string constant after "interval " keyword. I am sure there