Main   Products   Offshore Outsourcing   Customers   Partners   ContactUs  
JDBC Databases
  HXTT Access v7.1
  Buy Now
  HXTT Cobol v5.0
  HXTT DBF v7.1
  HXTT Excel v6.1
  HXTT Json v1.0
  HXTT Paradox v7.1
  HXTT PDF v2.0
  HXTT Text(CSV) v7.1
  HXTT Word v1.1
  HXTT XML v4.0
Offshore Outsourcing
Free Resources
  Firewall Tunneling
  Search Indexing Robot
  Conditional Compilation
  Password Recovery for MS Access
  Password Recovery for Corel Paradox
  Checksum Tool for MD5
  Character Set Converter
  Pyramid - Poker of ZYH
Heng Xing Tian Tai Lab of Xi'an City (abbr, HXTT)

DATEDIFF (exp,exp) syntax
2010-12-16 22:06:23
Hi All,
Can i have the example sql statement about the DATEDIFF(exp,exp)?
i tried the follwowing command. but it is not worked.
select count(*) from scanAnalysis a where TRIM(a.patient_key) = ? and
date(a.scan_date)= date(?) or datediff(date(a.scan_date),date(?))<=5 and a.scan_type IN (6,7);

date(?) =12/4/2005.

what is wrong in this query, Syntax error in expression getting.
Could you please provide mre the the sample query.


Re:DATEDIFF (exp,exp) syntax
HXTT Support
2010-12-16 22:45:10
If you're using PreparedStatement, you can use your sql, or datediff(date(a.scan_date),?)<=5 . You shouln't meet syntax error.

>date(?) =12/4/2005.
In sql, you need ' to enclose date string. For instance '2005-12-04'.

select date('12/4/2005');
will be detected and converted into select date('2005-12-04') .

Re:Re:DATEDIFF (exp,exp) syntax
2010-12-17 02:05:17

i tried this sql statement. it is working and giving the result.

SELECT a.patient_key, a.scan_date, datediff("d",a.scan_date,6/28/2010)>=5 FROM ScanAnalysis a where a.patient_key in ('1JTC04146R0883050','1JU40912IO0583050');

but if i give this statement , it is not working.

SELECT a.patient_key, a.scan_date, datediff(date(a.scan_date),6/28/2010)<=5 FROM ScanAnalysis a where a.patient_key in('1JTC04146R0883050','1JU40912IO0583050');


SELECT a.patient_key, a.scan_date, datediff("d",date(a.scan_date),6/28/2010)>=5 FROM ScanAnalysis a where a.patient_key in ('1JTC04146R0883050','1JU40912IO0583050');

What could be the reason?

Re:Re:Re:DATEDIFF (exp,exp) syntax
HXTT Support
2010-12-17 02:14:16 6/28/2010 will become 1.0660980810234541E-4 value, not a date value:(
You should use '6/28/2010' or '2010-06-28' or {d '2010-06-28'}.

2nd. DATEDIFF supports 2~3 parameter, but it means different format.
2 parameters will calculate only days.
DATEDIFF(expr,expr2): returns the number of days between the start date expr and the end date expr2. expr and expr2 are date or date-and-time expressions. Only the date parts of the values are used in the calculation.
3 parameters can calculate any part of date.
DATEADD(INTERVAL, expr, date), DATEDIFF (INTERVAL, date1, date2), DATEPART (INTERVAL, date) For instance, SELECT DateAdd('m', 3, date1) FROM test;

Search Key   Search by Last 50 Questions


Copyright © 2003-2019 Heng Xing Tian Tai Lab of Xi'an City. | All Rights Reserved. | Privacy | Legal | Sitemap