# java.sql.Timestamp =\> ElasticSearch long =\> C# System.DateTime

**URL:** <https://discuss.elastic.co/t/java-sql-timestamp-elasticsearch-long-c-system-datetime/59048>\
**Category:** Elasticsearch\
**Created:** [August 26, 2016, 2:48pm UTC](https://discuss.elastic.co/t/java-sql-timestamp-elasticsearch-long-c-system-datetime/59048 "2016-08-26T14:48:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fpopic](https://avatars.discourse-cdn.com/v4/letter/f/3ab097/32.png) [@fpopic](https://discuss.elastic.co/u/fpopic)\
**Post date:** [August 26, 2016, 2:48pm UTC](https://discuss.elastic.co/t/java-sql-timestamp-elasticsearch-long-c-system-datetime/59048/1 "2016-08-26T14:48:34Z")

</div>

I use `java.sql.Timestamp`  
`2014-12-27 00:00:00`

and ElasticSearch saves it as `1419634800000`

```
"EventDateLocal" : {
     "type" : "long"
},

```

and I want to read it in C# (via NEST) in DateTime

I tried

```
[Date(NumericResolution = NumericResolutionUnit.Milliseconds)] ?????
public DateTime? EventDateLocal { get; set; }

```

What should I put in annotation to get this effect automatically (long + unix =\> EventDate) :

```
foreach (var e in request.Documents)
{
	var start = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
	var date = start.AddMilliseconds(e.EventDateLocal.Value).ToLocalTime();
}

```

My NEST configuration is:

```
var client = new ElasticClient(new ConnectionSettings(new Uri(url))
	  .DefaultIndex(index)
	  .DefaultTypeNameInferrer(t => type)
);

```

If not with annotation is it possible somehow to tell NEST about long saved?

```
client.Map<Event>(m => m
  .AutoMap()
  .Properties(ps => ps
	  .Date(e => e
		  .Name("EventDateLocal")
		  .Format(????)
	  )
  )
);
```

---

<div class="post-metadata">

**Author:** ![KodrAus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kodraus/32/22798_2.png) [@KodrAus](https://discuss.elastic.co/u/KodrAus)\
**Post date:** [August 28, 2016, 7:13am UTC](https://discuss.elastic.co/t/java-sql-timestamp-elasticsearch-long-c-system-datetime/59048/2 "2016-08-28T07:13:43Z")

</div>

Does the [`epoch_millis` format](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html#built-in-date-formats) do what you need?

---

<div class="post-metadata">

**Author:** ![fpopic](https://avatars.discourse-cdn.com/v4/letter/f/3ab097/32.png) [@fpopic](https://discuss.elastic.co/u/fpopic)\
**Post date:** [August 28, 2016, 12:15pm UTC](https://discuss.elastic.co/t/java-sql-timestamp-elasticsearch-long-c-system-datetime/59048/3 "2016-08-28T12:15:19Z")

</div>

Hmm this could work but Is there any way to tell serializer that it should expect long instead of string,  
I don't know where to put that code (accessors get/set of field or anotation)?

> <https://gist.github.com/fpopic/8d7534f7bb3aabaf40ac8dca4c49f9e4>

And I'am not allowed to change mappings or anything in ES-db (read-only) I just want to specify different way of reading their longs

---

<div class="post-metadata">

**Author:** ![KodrAus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kodraus/32/22798_2.png) [@KodrAus](https://discuss.elastic.co/u/KodrAus)\
**Post date:** [August 30, 2016, 10:17am UTC](https://discuss.elastic.co/t/java-sql-timestamp-elasticsearch-long-c-system-datetime/59048/4 "2016-08-30T10:17:55Z")

</div>

Hmm that's a problem. I'd open an issue on the [.NET client GitHub repo](https://github.com/elastic/elasticsearch-net/issues), because you are technically supposed to be able to store and read longs as `epoch_millis`. There might be some supported way of doing it that I'm not aware of, they'll know better 🙂

You might have to fall back to your original approach afterall with a custom `DateTime` serialiser that deserialises a long to unix millis like [this SO question](http://stackoverflow.com/questions/19971494/how-to-deserialize-a-unix-timestamp-%CE%BCs-to-a-datetime).

---

<div class="post-metadata">

**Author:** ![fpopic](https://avatars.discourse-cdn.com/v4/letter/f/3ab097/32.png) [@fpopic](https://discuss.elastic.co/u/fpopic)\
**Post date:** [August 30, 2016, 10:59am UTC](https://discuss.elastic.co/t/java-sql-timestamp-elasticsearch-long-c-system-datetime/59048/5 "2016-08-30T10:59:04Z")

</div>

> <https://stackoverflow.com/questions/39175916/java-util-timestamp-elasticsearch-long-c-nest-datetime>

Yep thanks, man answered yesterday. =D

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:24pm UTC](https://discuss.elastic.co/t/java-sql-timestamp-elasticsearch-long-c-system-datetime/59048/6 "2017-07-05T22:24:05Z")

</div>


