Timestamp mapping

274 views
Skip to first unread message

Cristian Vanti

unread,
Oct 27, 2014, 12:23:40 PM10/27/14
to csharp-dr...@lists.datastax.com
The timestamp fields mapping to the C# DateTimeOffset is quite uncomfortable: the DateTimeOffset is not managed by the standard XMLSerializer and that's annoying. 
Moreover using CQLSH on computers located in different timezones means that I need to change the offset every time. I was thinking to use string or numeric fields to store datetimes as I used to do 20 years ago...

Jorge Bay Gondra

unread,
Oct 28, 2014, 5:53:24 AM10/28/14
to csharp-dr...@lists.datastax.com
Hi Cristian,
Timestamps in Cassandra are are encoded as 64-bit signed integers representing a number of milliseconds since the standard base time known as the epoch.
In C#, the most accurate representation would be DateTimeOffset, as it represents a moment in time. On the C# driver, you can use both DateTimeOffset and DateTime to retrieve or insert a timestamp value.

//valid
row.GetValue<DateTime>("time");
//valid
row.GetValue<DateTimeOffset>("time");

Thanks,
Jorge

On Mon, Oct 27, 2014 at 5:23 PM, Cristian Vanti <cva...@gmail.com> wrote:
The timestamp fields mapping to the C# DateTimeOffset is quite uncomfortable: the DateTimeOffset is not managed by the standard XMLSerializer and that's annoying. 
Moreover using CQLSH on computers located in different timezones means that I need to change the offset every time. I was thinking to use string or numeric fields to store datetimes as I used to do 20 years ago...

To unsubscribe from this group and stop receiving emails from it, send an email to csharp-driver-u...@lists.datastax.com.

Reply all
Reply to author
Forward
0 new messages