Main   Products   Offshore Outsourcing   Customers   Partners   ContactUs  
JDBC Databases
  HXTT Access v5.2
  Buy Now
  HXTT Cobol v2.1
  HXTT DBF v5.2
  HXTT Excel v4.2
  HXTT Paradox v5.2
  HXTT Text(CSV) v5.2
  HXTT XML v1.2
Offshore Outsourcing
Oracle Data Import/Export
DB2 Data Import/Export
Sybase Data Import/Export
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
Hongxin Technology & Trade Ltd. of Xiangtan City (abbr, HXTT)

DATEDIFF (exp,exp) syntax
2010-12-16 22:06:23.0
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.0
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.0

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.0 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


Address: 9 Station Rd., Xiangtan City, Hunan Province, P.R. China
Postcode: 411100
Phone: (86)731-58225727
Fax: (86)731-58225727
Copyright © 1999-2011 Hongxin Technology & Trade Ltd. | All Rights Reserved. | Privacy | Legal | Sitemap