I have string datetime in couchbase in this format(13/11/2016 10:45:00 MST). I want to convert it into this format “2016-11-13 10:45:00” so that i can pass the converted datetime to strToMillis().
I have written below query and it works fine on couchbase editor. Now, I want to translate it into java(1.8)code. How can I achieve this?
select * from Table_Name where STR_TO_MILLIS(DATE_FORMAT_STR(SUBSTR(DateTimeColomnName,6,4)|| ‘-’||SUBSTR(DateTimeColomnName,0,2)|| ‘-’ ||SUBSTR(DateTimeColomnName,3,2)|| ’ ’ ||SUBSTR(DateTimeColomnName,11,2) || ‘:’ ||SUBSTR(DateTimeColomnName,14,2)|| ‘:’ ||SUBSTR(DateTimeColomnName,17,2), ‘1111-11-11 01:01:01’)) <= DATE_ADD_MILLIS(NOW_MILLIS(), -2, ‘hour’)
Any help would really appreciated.
Hi @sachin.darade9 ,
Just to start, could you please let me know if you have tried to use our N1QL from SDK?
If not please refer to :https://docs.couchbase.com/java-sdk/2.7/scan-consistency-examples.html
Something like below should help you achieve what you wanted
Statement statement = select(“name”, “email”, “random”, “META(default).id”)
.from(“default”)
.where(x(“$1”).in(“name”));
//configure the query
N1qlParams params = N1qlParams.build()
//If this line is removed, the latest 'random' field might not be present
.consistency(ScanConsistency.REQUEST_PLUS);
N1qlQuery query = N1qlQuery.parameterized(statement, JsonArray.from("Brass"), params);
LOGGER.info("Expecting random: " + randomNumber);
@sachin.darade9
You’re asking about the query DSL in Couchbase Java SDK 2.x, I think? Before you invest too much time in it I should alert you to the fact that the query DSL has not been carried through to the newest iteration of the SDKs, 3.x, and that 2.x is not recommended for new deployments. But you can use the N1QL statement directly in either SDK 2.x or 3.x, e.g. cluster.query(“select * from Table_Name…”).