dateadd

Using sql DATEADD function in java

拥有回忆 提交于 2019-11-29 11:06:58
When I run queries using DATEADD it seems that the database does not recognize this function. also when I just run select DATEADD(Month, -3, GETDATE()) I'm getting: Error code -1, SQL state 42X01: Syntax error: Encountered "<EOF>" at line 1, column 36. I added the JAR file from hsqldb-2.2.9 as you can see What am I missing here? Derby does not have a DATEADD function. You need to use the JDBC function timestampadd to achieve this: select {fn TIMESTAMPADD(SQL_TSI_MONTH, -3, CURRENT_TIMESTAMP)} from sysibm.sysdummy1 An alternative to using sysdummy1 is the ANSI standard values clause which works

MySQL - DATE_ADD month interval

落花浮王杯 提交于 2019-11-29 10:47:34
问题 I face a problem with the function DATE_ADD in MySQL. My request looks like this : SELECT * FROM mydb WHERE creationdate BETWEEN "2011-01-01" AND DATE_ADD("2011-01-01", INTERVAL 6 MONTH) GROUP BY MONTH(creationdate) The problem is that, in the results, -I think- because June has only 30 days, the function doesn't work properly as I have the results of the first of July . Is there a way to tell DATE_ADD to work well and take the right number of days within a month? 回答1: DATE_ADD works just

SQL获取当月天数的几种方法

大城市里の小女人 提交于 2019-11-29 05:42:01
日期直接减去int类型的数字 等于 DATEADD(DAY,- 数字,日期) 下面三种方法: 1,日期加一个月减去当前天数,相当于这个月最后一天的日期。然后获取天数。(注意,不能用这种方式:当前日期减去当前天数,再加一个月,新日期不一定是当前月的最后一天的日期。比如当前月是3月。错误:select day(dateadd(month,1,getdate()-day(getdate())))) select day(dateadd(mm,1,getdate())-day(getdate())) 2,convert把日期转换成120格式的是 "2011-1-1"这种格式。 最终也是得到这个月最后一天。然后获取天数。 select day( dateadd(day,-1, dateadd(month,1,convert(char(07),getdate(),120)+'-01')) ), 3,下个月的今天与和今天的日期差 。 (这个月剩下的日期+已经过去的日期) select datediff(dd , GETDATE(), dateadd(mm, 1,GETDATE())) 4,下面这个方法很犀利。 先得到上个月的最后一天,然后加一个天数(黑色标记),这个天数只要大于一个月的天数即可。但不要大于两个月的天数。 这样就可以生成下个月的日期。然后用这个天数减去新生成的日期多出来的天数

SQL Server按时间分段统计数据

一曲冷凌霜 提交于 2019-11-28 21:49:05
--按小时查询 select DATEADD(HOUR, DATEDIFF(HOUR,0,[Date]), 0) as EnterDate,sum([count]) FROM Table1 where roleid = 3 and [Date] > '2012-7-26 20:00:00.00' group by DATEADD(HOUR, DATEDIFF(HOUR,0,[Date]), 0) order by [Date] desc   SQL Server DATEADD() 函数 DATEADD() 函数在日期中添加或减去指定的时间间隔。 DATEADD(datepart,number,date)date 参数是合法的日期表达式。number 是您希望添加的间隔数;对于未来的时间,此数是正数,对于过去的时间,此数是负数。datepart 参数是时间的单位。 SQL Server DATEDIFF() 函数 DATEDIFF() 函数返回两个日期之间的时间间隔。 DATEDIFF(datepart,startdate,enddate) startdate 和 enddate 参数是合法的日期表达式。 示例: 1 SELECT DATEDIFF(day,'2008-12-29','2008-12-30') AS DiffDate结果为1 2 SELECT DATEDIFF

SQL Server 2005 Using DateAdd to add a day to a date

徘徊边缘 提交于 2019-11-28 20:00:32
How do I in SQL Server 2005 use the DateAdd function to add a day to a date Use the following function: DATEADD(type, value, date) date is the date you want to manipulate value is the integere value you want to add (or subtract if you provide a negative number) type is one of: yy, yyyy: year qq, q: quarter mm, m: month dy, y: day of year dd, d: day wk, ww: week dw, w: weekday hh: hour mi, n: minute ss or s: second ms: millisecond mcs: microsecond ns: nanosecond SELECT DATEADD(dd, 1, GETDATE()) will return a current date + 1 day http://msdn.microsoft.com/en-us/library/ms186819.aspx DECLARE

How to select last one week data from today's date

只愿长相守 提交于 2019-11-28 08:55:25
How to select week data (more precisely, last 7 days data) from the current date in the fastest way as I have millions or rows in the table. I have a time stamp of created_date in sql table. I have tried this SELECT Created_Date FROM Table_Name WHERE Created_Date >= DATEADD(day,-7, GETDATE()) I have two question: Is this query is correct? Is this is the fastest way to get the last seven day data from a table having millions of rows ? Yes, the syntax is accurate and it should be fine. Here is the SQL Fiddle Demo I created for your particular case create table sample2 ( id int primary key,

Using sql DATEADD function in java

时间秒杀一切 提交于 2019-11-28 05:12:35
问题 When I run queries using DATEADD it seems that the database does not recognize this function. also when I just run select DATEADD(Month, -3, GETDATE()) I'm getting: Error code -1, SQL state 42X01: Syntax error: Encountered "<EOF>" at line 1, column 36. I added the JAR file from hsqldb-2.2.9 as you can see What am I missing here? 回答1: Derby does not have a DATEADD function. You need to use the JDBC function timestampadd to achieve this: select {fn TIMESTAMPADD(SQL_TSI_MONTH, -3, CURRENT

【sqlServer】常用语句整理

此生再无相见时 提交于 2019-11-28 01:11:51
--------------------------------------------------------- --查询数据库中包含某字段的所有表名 --objName表名 根据xtpe='u'这个是查询表名 use BigData_ODS GO select object_name(id) objName,Name as 列名 from syscolumns where (name like'字段名') and id in(select id from sysobjects where xtype='u') order by objname ------------------------------------------------------------ --查看所有表对应的数据量 SELECT a.name AS 表名, MAX(b.rows) AS 记录条数 FROM sys.sysobjects AS a INNER JOIN sys.sysindexes AS b ON a.id = b.id WHERE (a.xtype = 'u') GROUP BY a.name ORDER BY 记录条数 DESC ------------------------------------------------------------ --查看数据库的总数据量

Add Number of days column to Date Column in same dataframe for Spark Scala App

随声附和 提交于 2019-11-27 16:12:10
I have a dataframe df of columns ("id", "current_date", "days") and I am trying to add the the " days " to " current_date " and create a new dataframe with new column called " new_date " using spark scala function date_add() val newDF = df.withColumn("new_Date", date_add(df("current_date"), df("days").cast("Int"))) But looks like the function date_add only accepts Int values and not columns . How can get the desired output in such case? Are there any alternative functions i can use to get the desired output? spark version: 1.6.0 scala version: 2.10.6 A small custom udf can be used to make this

sql 日期函数

淺唱寂寞╮ 提交于 2019-11-27 12:43:33
sql 日期函数 --日期类型函数 --date datatime datatime2 --date 只存储 年月日 --datetime 存储年月日时分秒毫秒 --dataetime2 时间范围更广 --日期函数 --dateAdd(datepart,number,date) select DATEADD ( DAY , 200 , GETDATE ( ) ) --默认datetime 范围比较小 select stuName , DATEADD ( YEAR , - stuAge , GETDATE ( ) ) from Tbstudent --计算时间差 --datediff(datepart,date1,date2) --date1是较早的时间 date2 是较晚的时间 select DATEDIFF ( YEAR , '1999-07-24' , GETDATE ( ) ) --计算年龄 --select DATEDIFF(YEAR,birthday,GETDATE()) --day() month() year() --获取日期 来源: https://blog.csdn.net/qq_44983621/article/details/99674653