Main Site Documentation

DateTime fields in SQLite


#1

From what I’ve read on the forum SQLite for ChipworkX doesn’t support the DateTime field. Is this accurate and if so are there intentions to add support for it?


#2

It is accurate. You can store it as strings.


#3

DateTime has a Ticks property - This is stored as a long (64bit integer) and can represent dates from DateTime.MinValue to DateTime.MaxValue with 100ns accuracy.

I can only assume that both the ticks property and the constructor which takes a number of ticks is in NETMF.

Edit: I checked and Ticks is available in NETMF.


#4

I made a timestamp myself:


public static int dateToUnixTimestamp(DateTime date) {
  DateTime referenceDate = new DateTime(1970, 1, 1, 0, 0, 0, 0);  
  TimeSpan ts = new TimeSpan(date.Ticks - referenceDate.Ticks);  
  return (int)(ts.Ticks/TimeSpan.TicksPerSecond);
}


public static DateTime unixTimestampToDate(int timestamp) {
  DateTime referenceDate = new DateTime(1970, 1, 1, 0, 0, 0, 0);
  referenceDate = referenceDate.AddSeconds(timestamp);
  return referenceDate;
}


#5

@ anm - code tags, please :slight_smile:


#6

ooops - did I forget them? :o


#7

There was an error in the code - I just corrected it…