sql-date-functions

Oracle date function for the previous month

我是研究僧i 提交于 2019-12-03 23:53:52
I have the query below where the date is hard-coded. My objective is to remove the harcoded date; the query should pull the data for the previous month when it runs. select count(distinct switch_id) from xx_new.xx_cti_call_details@appsread.prd.com where dealer_name = 'XXXX' and TRUNC(CREATION_DATE) BETWEEN '01-AUG-2012' AND '31-AUG-2012' Should I use sysdate-15 function for that? Priti Getkewar Joshi Modifying Ben's query little bit, select count(distinct switch_id) from xx_new.xx_cti_call_details@appsread.prd.com where dealer_name = 'XXXX' and creation_date between add_months(trunc(sysdate,

Difference between two dates in postgresql

北慕城南 提交于 2019-12-02 03:57:39
Function: CREATE FUNCTION diff(d1 date,d2 date) RETURNS int AS $$ BEGIN IF d1 = NULL THEN RETURN SELECT extract(year from age(current_date,d2)); ELSE RETURN SELECT extract(year from age(d1,d2)); END IF; END $$ language plpgsql; My requirement is to find the difference between two dates in years. So, I write the above function. Here, if d1 is NULL then it is assigned with current date. But, it produce error like as shown below. ERROR: syntax error at or near "SELECT" LINE 1: SELECT SELECT extract(year from age(current_date, $1 )) QUERY: SELECT SELECT extract(year from age(current_date, $1 ))

How to parse String to java.sql.date

谁说胖子不能爱 提交于 2019-12-01 17:16:05
I have a String String s = "01 NOVEMBER 2012"; Then I want parse it to sqlDate. And insert it into the database. Is it possible to parse that string to sqlDate?!?! Yup, sql date format is "yyyy-mm-dd" Use SimpleDateFormat to parse String date to java.util.Date java.util.Date utilDate = new SimpleDateFormat("dd MMM yyyy").parse("01 NOVEMBER 2012"); and then convert it to java.sql.Date using millis java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); Expanding on Jigar Joshi answer. This code has been able to handle whatever I've needed. import java.sql.Date; import java.text

How to find a time delta of a datatime row in mysql?

允我心安 提交于 2019-11-30 15:43:53
I have a column in a database which provides datetime stamps for series of sensor readings. I'd like to segment those reading into unbroken, continuous sets of sensor readings. If a sensor reading is broken, then there will be a discontinuity in the date time column. And so I'd like to perform a query on the datetime column and then compute the difference between consecutive readings. Supposing my query is: select sensor_time from sensor_table limit 10; I'd get: +---------------------+ | sensor_time | +---------------------+ | 2009-09-28 07:08:12 | | 2009-09-28 07:08:40 | | 2009-09-28 07:09:10

Java date to sql date

拜拜、爱过 提交于 2019-11-30 06:05:20
问题 How can I store a specific date from java to my database? (Not only the date today, but also some dates that the user wants to specifiy) try { SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); Date date = dateFormat.parse(tf.getText()); String d = dateFormat.format(date); String str = "insert into tableName(tDate) values (?)"; con = mysqlConnection.dbConnector(); prs = con.prepareStatement(str); prs.setDate(1, // dont know what to put here); int rsUpdate = prs.executeUpdate();

How to find a time delta of a datatime row in mysql?

隐身守侯 提交于 2019-11-29 23:07:50
问题 I have a column in a database which provides datetime stamps for series of sensor readings. I'd like to segment those reading into unbroken, continuous sets of sensor readings. If a sensor reading is broken, then there will be a discontinuity in the date time column. And so I'd like to perform a query on the datetime column and then compute the difference between consecutive readings. Supposing my query is: select sensor_time from sensor_table limit 10; I'd get: +---------------------+ |

how to create ISO-8601 gregorian date table in postgres

偶尔善良 提交于 2019-11-29 16:02:36
I'm looking to create a date table in a postgres database. The sample data is expected to look like this: date key = 00001 calendar_date= 1/1/2015 week_num= 1 month_num= 1 month_name= Jan quarter_num= 1 calendar_year= 2015 iso_dayofweek= 4 dayofweek_name= Thursday Is there a function or SQL that I can get help with to create a date gregorian ISO-8601 table? I am looking to auto generate this if possible. Any help in this direction would be appreciated. see the below example SELECT mydate calendar_date ,EXTRACT(WEEK FROM mydate) week_num ,EXTRACT(month FROM mydate) month_num ,to_char(mydate,

Mysql DATE_SUB(NOW(), INTERVAL 1 DAY) 24 hours or weekday?

本秂侑毒 提交于 2019-11-28 23:21:21
I am trying to get the totaal amount of registerd users per day. At the moment i am using this $sql = "SELECT name, email FROM users WHERE DATE_SUB(NOW(), INTERVAL 1 DAY) < lastModified" but i am not sure if this works per day or per 24 hours? For example, a user who registered 22 hours ago shouldn't be returned i just like the user of today(=Tuesday) lastModified is, presumably, a datetime. To convert this into a date you can simply wrap it in DATE() i.e. DATE(lastModified) . DATE() returns the date part of a datetime value which is effectively 00:00 on that day. SELECT name, email FROM users

Java date to sql date

蓝咒 提交于 2019-11-28 14:41:36
How can I store a specific date from java to my database? (Not only the date today, but also some dates that the user wants to specifiy) try { SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); Date date = dateFormat.parse(tf.getText()); String d = dateFormat.format(date); String str = "insert into tableName(tDate) values (?)"; con = mysqlConnection.dbConnector(); prs = con.prepareStatement(str); prs.setDate(1, // dont know what to put here); int rsUpdate = prs.executeUpdate(); con.close(); prs.close(); } catch(ParseException exx) { System.err.println(exx); Use prs.setDate( 1,

Mysql DATE_SUB(NOW(), INTERVAL 1 DAY) 24 hours or weekday?

╄→尐↘猪︶ㄣ 提交于 2019-11-27 13:49:06
问题 I am trying to get the totaal amount of registerd users per day. At the moment i am using this $sql = "SELECT name, email FROM users WHERE DATE_SUB(NOW(), INTERVAL 1 DAY) < lastModified" but i am not sure if this works per day or per 24 hours? For example, a user who registered 22 hours ago shouldn't be returned i just like the user of today(=Tuesday) 回答1: lastModified is, presumably, a datetime. To convert this into a date you can simply wrap it in DATE() i.e. DATE(lastModified) . DATE()