0

I have ISO8601 date time format (e.g 2000-02-29T12:45:00+02:00). I must convert it to double.

I'm getting this values from database:

std::string _date = ((char*)sqlite3_column_text(statement, 0) != NULL) ? (char*)sqlite3_column_text(statement, 0) : "0";

And I try convert like that:

value.dateTime = atof(_date.c_str());

For all of dates in database I get the same values

Mat
  • 1
  • 2
  • `atof` is going to convert the first number it finds (i.e. the year) and ignore all the rest. You'll need something much more sophisticated. – Mark Ransom Dec 02 '14 at 18:54
  • atof converts a C-string to a double, assuming it can be done. When letters and such are in the string, it doesn't make sense. To convert the date-time to a double, you need to decide how that double is defined. When does it cross zero, does 1.0 in your double correspond to one second, one day, etc? There are a few standard ways to do this: unix time and julian date. I suggest you look into them. – Rob Falck Dec 02 '14 at 18:55
  • 2
    Probably the easiest way will be to get the database itself to do it: https://www.sqlite.org/lang_datefunc.html – Mark Ransom Dec 02 '14 at 18:58
  • 2
    To **what** double? A datetime is a date/time specification, but a double is just a number, we'll need context to know how those double values are to be interpreted before we know how to convert them. – outlyer Dec 02 '14 at 19:00
  • This datetime will be use for x-axis as data it must be as double. – Mat Dec 02 '14 at 19:05
  • I think I can use numbers instead this dates. This numbers will be row's number, latter I can invoke date from any row in database, because I will know which row interesting me. – Mat Dec 02 '14 at 19:15

0 Answers0