Discussion:
How to work with Dates in Datomic
Wian Needham
2015-10-07 14:04:59 UTC
Permalink
Hi Guys

I am trying out Datomic and building a POC for a project I am working on. I
am also fairly new to Datomic and might ask a stupid question or 2 :)

I have to added an attribute "employee/effDate" and I have set the type to
":db.type/instant", Next I would like to add data very similar to the
Seattle community tutorial but I cannot pass a date in my data file.

Below is my data that i would like to load and I have no idea what format
or data to pass for the effective date field
{
; add a temp key for the entiry
:db/id #db/id[:db.part/user -2],
:employee/id 2,
*:employee/effDate XXXXXX,* ; what should the format be for this?
"22015-01-01T00:00:00.00Z"?
:employee/firstName "Peter",
:employee/lastName "Jones"
}

As a next Followup question, I would also like to know how do i go about
querying the data for a date range via Java.
For example get all the entries where the effective date is between
01.01.2015 -> 01.04.2015.

Thanks in advance and Kind regards
--
You received this message because you are subscribed to the Google Groups "Datomic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to datomic+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Gary Verhaegen
2015-10-07 21:04:15 UTC
Permalink
For the data file, you can use the edn syntax:

#inst "1985-04-12T23:20:50.52Z"

I'm not sure about your second question, though. I *think* you can use >
and < directly in Datomic queries to compare dates, but I'm in no position
to test right now.
Post by Wian Needham
Hi Guys
I am trying out Datomic and building a POC for a project I am working on.
I am also fairly new to Datomic and might ask a stupid question or 2 :)
I have to added an attribute "employee/effDate" and I have set the type to
":db.type/instant", Next I would like to add data very similar to the
Seattle community tutorial but I cannot pass a date in my data file.
Below is my data that i would like to load and I have no idea what format
or data to pass for the effective date field
{
; add a temp key for the entiry
:db/id #db/id[:db.part/user -2],
:employee/id 2,
*:employee/effDate XXXXXX,* ; what should the format be for this?
"22015-01-01T00:00:00.00Z"?
:employee/firstName "Peter",
:employee/lastName "Jones"
}
As a next Followup question, I would also like to know how do i go about
querying the data for a date range via Java.
For example get all the entries where the effective date is between
01.01.2015 -> 01.04.2015.
Thanks in advance and Kind regards
--
You received this message because you are subscribed to the Google Groups "Datomic" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Datomic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to datomic+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Matthew Boston
2015-10-08 13:24:57 UTC
Permalink
For the second portion of you question, you can do something like:

(d/q '[:find [?employee ...]
:in $ ?start ?end
:where
[?employee :employee/effDate ?effDate]
[(.after ^java.util.Date ?effDate ?start)]
[(.before ^java.util.Date ?effDate ?end)]]
db
start
end)

This will be exclusive of ?start and ?end so you can adjust the query as
you need it.
Post by Wian Needham
Hi Guys
I am trying out Datomic and building a POC for a project I am working on.
I am also fairly new to Datomic and might ask a stupid question or 2 :)
I have to added an attribute "employee/effDate" and I have set the type to
":db.type/instant", Next I would like to add data very similar to the
Seattle community tutorial but I cannot pass a date in my data file.
Below is my data that i would like to load and I have no idea what format
or data to pass for the effective date field
{
; add a temp key for the entiry
:db/id #db/id[:db.part/user -2],
:employee/id 2,
*:employee/effDate XXXXXX,* ; what should the format be for this?
"22015-01-01T00:00:00.00Z"?
:employee/firstName "Peter",
:employee/lastName "Jones"
}
As a next Followup question, I would also like to know how do i go about
querying the data for a date range via Java.
For example get all the entries where the effective date is between
01.01.2015 -> 01.04.2015.
Thanks in advance and Kind regards
--
You received this message because you are subscribed to the Google Groups "Datomic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to datomic+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Lucas Cavalcanti
2015-10-08 14:03:07 UTC
Permalink
<, >, <=, >= work for dates as well.
Post by Matthew Boston
(d/q '[:find [?employee ...]
:in $ ?start ?end
:where
[?employee :employee/effDate ?effDate]
[(.after ^java.util.Date ?effDate ?start)]
[(.before ^java.util.Date ?effDate ?end)]]
db
start
end)
This will be exclusive of ?start and ?end so you can adjust the query as
you need it.
Post by Wian Needham
Hi Guys
I am trying out Datomic and building a POC for a project I am working on.
I am also fairly new to Datomic and might ask a stupid question or 2 :)
I have to added an attribute "employee/effDate" and I have set the type
to ":db.type/instant", Next I would like to add data very similar to the
Seattle community tutorial but I cannot pass a date in my data file.
Below is my data that i would like to load and I have no idea what format
or data to pass for the effective date field
{
; add a temp key for the entiry
:db/id #db/id[:db.part/user -2],
:employee/id 2,
*:employee/effDate XXXXXX,* ; what should the format be for this?
"22015-01-01T00:00:00.00Z"?
:employee/firstName "Peter",
:employee/lastName "Jones"
}
As a next Followup question, I would also like to know how do i go about
querying the data for a date range via Java.
For example get all the entries where the effective date is between
01.01.2015 -> 01.04.2015.
Thanks in advance and Kind regards
--
You received this message because you are subscribed to the Google Groups "Datomic" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Datomic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to datomic+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Wes Morgan
2016-10-13 15:54:12 UTC
Permalink
Sorry to resurrect an old thread, but I'm curious if this is documented
anywhere, what it's doing under the hood, etc.?

Since in a regular old Clojure REPL, this happens:

(< #inst"2016-01-01" #inst"2016-10-13")
ClassCastException java.util.Date cannot be cast to java.lang.Number
clojure.lang.Numbers.lt (Numbers.java:221)

I'm curious what is going w/in Datomic to make this work. I do believe that
it works and in fact am using it in production even now. Just curious about
the inner workings.
Post by Lucas Cavalcanti
<, >, <=, >= work for dates as well.
Post by Matthew Boston
(d/q '[:find [?employee ...]
:in $ ?start ?end
:where
[?employee :employee/effDate ?effDate]
[(.after ^java.util.Date ?effDate ?start)]
[(.before ^java.util.Date ?effDate ?end)]]
db
start
end)
This will be exclusive of ?start and ?end so you can adjust the query as
you need it.
Post by Wian Needham
Hi Guys
I am trying out Datomic and building a POC for a project I am working
on. I am also fairly new to Datomic and might ask a stupid question or 2 :)
I have to added an attribute "employee/effDate" and I have set the type
to ":db.type/instant", Next I would like to add data very similar to the
Seattle community tutorial but I cannot pass a date in my data file.
Below is my data that i would like to load and I have no idea what
format or data to pass for the effective date field
{
; add a temp key for the entiry
:db/id #db/id[:db.part/user -2],
:employee/id 2,
*:employee/effDate XXXXXX,* ; what should the format be for this?
"22015-01-01T00:00:00.00Z"?
:employee/firstName "Peter",
:employee/lastName "Jones"
}
As a next Followup question, I would also like to know how do i go about
querying the data for a date range via Java.
For example get all the entries where the effective date is between
01.01.2015 -> 01.04.2015.
Thanks in advance and Kind regards
--
You received this message because you are subscribed to the Google Groups
"Datomic" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Datomic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to datomic+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...