Neo4j Date conversion and comparison? - ms-access

I was working with MS access database.MY datetime is now like "05-03-2016 14:55:20" .I need to convert it into datetime format in neo4j.1.How to do it ? 2.After conversion I need to use date filter i.e I want to find all nodes created between 2 dates.How to do it ?

If Neo4j is pulling data from Access query, construct field in query that calculates date to a string that Neo4j can then convert to date with its DateTime function.
Format([fieldname], "yyyy/mm/dd hh:nn:ss")

You can use the APOC function apoc.date.parse() to convert your MS Access datetime string into the number of seconds from the UNIX epoch, and then construct a neo4j datetime from that value. For example, this will return a neo4j datetime that represents your sample time string:
RETURN datetime({
epochSeconds: apoc.date.parse('05-03-2016 14:55:20', 's', 'MM-dd-yyyy HH:mm:ss')
})
A neo4j temporal type can only be compared directly to the same type. For instance, to compare a datetime X to a date Y, you can convert X to a date before doing the comparison. The following sample query will return true:
WITH
datetime({
epochSeconds: apoc.date.parse('05-03-2016 14:55:20', 's', 'MM-dd-yyyy HH:mm:ss')
}) AS X,
date('2016-05-04') AS Y
RETURN date({date: X}) <= Y

Related

to_timestamp() passing the json data which is int and has unix timestamp not working in postgresql

info{
...
created_at:'1667801192'
}
select to_timestamp(info->'created_at') from booking;
info column has unix timestamp
expecting the whole column to convert as date
SQL is a typed language; every expression has a data type. The type of info->'created_at' is json or jsonb (depending on the type of info), and there is no function to_timestamp that accepts these data types as input. You will have to perform a type cast:
to_timestamp(CAST (info ->> 'created_at' AS double precision))

Can't execute string to date conversion

Could anyone point what to read, because I'm stuck with trivial issue. I store data in JSON format and I have a key with string that consists of a non ISO format datetime value, e.g. '%d-%m-%Y %H:%i:%S'
I've tried function STR_TO_DATE on string "17-12-2019 13:49:50" and it returned SQL datetime result, but when I use it in function
DELETE FROM queue WHERE
ts = CASE
WHEN type = 'entry' THEN HOUR(TIMEDIFF (NOW(), STR_TO_DATE(JSON_EXTRACT(request, "$.date_event"),'%d-%m-%Y %H:%i:%S'))) > 72
SQL raises
Incorrect datetime value: '"07-12-2016 18:21:59"' for function
str_to_date
When I try statement SELECT STR_TO_DATE(JSON_EXTRACT(request, "$.date_event"),'%d-%m-%Y %H:%i:%S') MySQL returns null
Your issue is caused by the double quotes returned around the extracted value. You need to either unquote the extracted value e.g.
JSON_UNQUOTE(JSON_EXTRACT(request, "$.date_event"))
or using shorthand notation
request->>'$.date_event'
Or add the double quotes into the STR_TO_DATE template i.e.
STR_TO_DATE(JSON_EXTRACT(request, "$.date_event"),'"%d-%m-%Y %H:%i:%S"'))
Demo on dbfiddle

Couchbase convert epoch to ISO

I'm struggling to convert Epoch to ISO datetime with Couchbase N1QL. Couchbase stores etoch time with milliseconds and I need full ISO8 format YYY-MM-DDThh:mm:ss.S. I have tried:
SELECT DATE_PART_MILLIS(1463284740000, 'year'), DATE_PART_MILLIS(1463284740000, 'month'), DATE_PART_MILLIS(1463284740000, 'day')
but it obviously returns json-like response. I tries to concatenate like SELECT DATE_PART_MILLIS(1463284740000, 'year') || DATE_PART_MILLIS(1463284740000, 'month') || DATE_PART_MILLIS(1463284740000, 'day')
But it renders nothing back
[
{
"$1": null
}
]
Any suggestion?
In Couchbase you can store the time as number (In Milliseconds)
or string as ISO-8601 format. It provides many date functions to work on
ISO-8601 format as described at
https://developer.couchbase.com/documentation/server/current/n1ql/n1ql-language-reference/datefun.html
SELECT MILLIS_TO_STR(1463284740000);
DATE_PART_MILLIS(date1, part [, tz])
Extracts the value of a given date component from an Epoch/UNIX timestamp value.
Return Value -- An integer representing the value of the component extracted from the timestamp.
String concatenation expects string, Add TOSTRING around the function like
SELECT TOSTRING(DATE_PART_MILLIS(1463284740000, 'year')) || "-" ||
TOSTRING(DATE_PART_MILLIS(1463284740000, 'month')) || "-" ||
TO_STRING(DATE_PART_MILLIS(1463284740000, 'day'));

Selecting DateTime from a query

I have the following linq to sql query:
DateTime linqdate = (from de in dvlist
where de.DataValue == value
select de.DateTime);
I want to get the date value form database in a datetime variable but I got the following error:
cannot implicitly convert type
'System.Collections.Generic.IEnumerable'
to 'System.DateTime'
any ideas where the problem is? thanks in advance
A Linq query returns an IEnumerable<T> that you can iterate or you can convert it to another type of object (using some extension methods)
In order to get what you want you should do something like this :
var dateTime=(from de in dvlist
where de.DataValue == value
select de.DateTime).FirstOrDefault();
this way you are returning the first element of your enumerable object, or the default value for that type (T, in this case DateTime) if there is no match in the query.

How do you compare dates in a LINQ query?

I am tring to compare a date from a asp calendar control to a date in the table.... here's what i have... it doesn't like the == ?
var query = from details in db.TD_TravelCalendar_Details
where details.StartDate == calStartDate.SelectedDate
&& details.EndDate == calEndDate.SelectedDate
select details;
In order for your query to work both details.StartDate and calStartDate.SelectedDate must be typed as System.DateTime.
What error are you receiving? Most likely one of these properties is a string and will need to be parsed into a DateTime instance for comparison.
What is the Type of details.StartDate and details.EndDate? Is it String? Maybe that's the problem. If the database type is String you should Parse the Date String into a DateTime and compare it with the calendar's selected date then.