We created a small table `test_timestamp` on our Fivewin Cloud server, which is accessible to all of us for demo purposes.
This is the full table data.
We want to extract rows with timestamp between 01-02-2022 and 04-02-2022 (both days inclusive). We used where clause like this:
SELECT * FROM test_timestamp WHERE col_timestamp >= '2022-02-01' AND col_timestamp < '2022-02-05'
This is the result:
You can yourself run this program. Copy the program given below to \fwh\samples folder and build and run with buildh.bat or buildx.bat.
#include "fivewin.ch"
function Main()
local oCn, oRs
local t
SET DATE ITALIAN
SET CENTURY ON
oCn := FW_DemoDB( 6 )
if oCn == nil
? "connect fail"
return nil
endif
oCn:lShowErrors := .t.
oRs := oCn:RowSet( "SELECT * FROM test_timestamp" )
XBROWSER oRs TITLE "FULL TABLE"
oRs:Close()
oRs := oCn:RowSet( "SELECT * FROM test_timestamp WHERE col_timestamp >= '2022-02-01' AND col_timestamp < '2022-02-05'" )
XBROWSER oRs TITLE "01 FEB TO 04 FEB"
oRs:Close()
oCn:Close()
return nil
You can even modify the program and test whatever you like.
This is the structure of the table:
CREATE TABLE `test_timestamp` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`COL_DATETIME` DATETIME(3) DEFAULT NULL,
`COL_TIMESTAMP` TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP(3),
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8