Recent

Author Topic: SOLVED StrToDateTime result (ver. from 0.9 to 1.1) and Julian day in sqlite DB  (Read 6506 times)

agb

  • New member
  • *
  • Posts: 7
Hi!

Code:
===
dtf.DateSeparator := '-';
      dtf.TimeSeparator := ':';
      dtf.ShortDateFormat := 'yyyy-MM-dd';
      dtf.ShortTimeFormat := 'hh:mm:ss';
      dt := StrToDateTime(s, dtf);
...
DM.quRecords.InsertRecord([id,
                                 dt,    // whendate
                                 data.Strings[1]]);   // tel 
...
===
I got Database records with different values. One year before:
id  whendate
--  --------
xx 40994.59472

And after change Lazarus version:
id  whendate
--  --------
xx 2456013,119

All records are in one sqlite datebase now. And I do not know what to do to fix this.
SQLite now normally converts 2456288,423 to '2012-12-26', so I need to convert old records to this format.
« Last Edit: December 28, 2012, 02:57:12 pm by agb »

wjackson153

  • Sr. Member
  • ****
  • Posts: 267
Re: StrToDateTime result change on road from 0.9 to 1.1 version
« Reply #1 on: December 27, 2012, 10:40:44 pm »
Not sure If I understand what your asking entirely :

but perhaps this would help

dtf := FormatDateTime('yyyyy-mm-dd',DATE) ;
Lazarus 1.1 r39490 CT FPC 2.7.1 i386-linux KDE
Linux Mint 14 KDE 4

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: StrToDateTime result change on road from 0.9 to 1.1 version
« Reply #2 on: December 28, 2012, 09:53:12 am »
wjackson's advice sounds good. AFAIR, behaviour of default date/time delimiters has changed in previous FPC versions. No idea if this affects you...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

agb

  • New member
  • *
  • Posts: 7
Two functions returns two different values:
StrToDateTime(s, dtf) in code:
===
dt := StrToDateTime(s, dtf);
DM.quRecords.InsertRecord([id, dt]);
===
inserts Julianday numbers approx 2456013,119 to database


The similar function StrToDate in code:
===
s := s + 'round(whendate-0.5) = ' + IntToStr(trunc(StrToDate(edDate.Text)));
===
add number approx 40995 (numeric date in Excel) to string. (edDate: TDateEdit)

----------
solution is:
s := s + 'round(whendate - 1) = ' + IntToStr(trunc(DateTimeToJulianDate(edDate.Date)));

----------
And in lazarus 0.9 StrToDateTime puts to database values approx 40995 (like date in Excel).
« Last Edit: December 28, 2012, 02:58:30 pm by agb »

Zoran

  • Hero Member
  • *****
  • Posts: 1949
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: StrToDateTime result change on road from 0.9 to 1.1 version
« Reply #4 on: December 28, 2012, 03:38:45 pm »
AFAIR, behaviour of default date/time delimiters has changed in previous FPC versions.

Uh... Is it documented somewhere?

In the pages to which this page links I cannot find it.
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12262
  • FPC developer.
That page is about new features, not general changes

Every FPC release has a "User changes" page that tries to document the changes needed to user code when changing FPC version. Specially for major FPC version changes (2.4.x -> 2.6.x) it can be worthwhile to investigate.

The problem you mention is in the user changes for 2.6.0:

http://wiki.freepascal.org/User_Changes_2.6.0#SQLDB.2FTSQLite3Connection_now_stores_date.5Btime.5D_values_as_Julian_day_numbers

The entry contains a SQL query to convert such columns

agb

  • New member
  • *
  • Posts: 7
marcov, thank you!

 

TinyPortal © 2005-2018