Rafi Cohen wrote:
Hi, I hope this question is not off-topic for this list.
I'm recieveing, occasionally, a .csv file from a source which I need to
process accordcing to some criteria and either insert, delet or update
it's rows into a database. One of it's criterias is date comparison.
In other words, proceeding differently when the date/time mentioned on a
specific row is a past date or future date comparing with the current
date/time.
My problem is the format in which I recieve the date and time:
"HH:MM:SS, YYYY--mm-dd".
This means separate fileds, one for time and one for date.
If the format was: "YYYY-mm-dd HH:MM:SS", I could call strptime to stor
this in a struct tm, then cakk mktime to get this in a time_t varialbe
and then call difftime with the current date/time to make the comparison
(I'm using C as programmikng language on Linux).
So, my question is: should I unify the 2 strings into one to obtain the
second format and then proceed as I explained above, or is there a way
to compare the date with the current date separately and the time with
the current time separately in case the dates are equal?
If the conclusion will be to uify the strings into one, should I create
a table with a single date/time column or still keep the 2 fileds
separately in my sql table?
Thanks, Rafi.

Rafi,

It depends. :-)

It depends on what you think is more important, execution speed, database size, simplicity of coding, etc...

Assuming the date format you gave has a typo and there is really only one '-' between the year and month in your existing fields, you should be able to do your date comparisons in sqlite. Use concatenation to build a single date and time string. With your date and time in ISO format you can then use string comparisons as date comparisons

   select
       case when (date || ' ' || time) < ?limit_date
       then field_one
       else field_two
       end
   from my_table


HTH
Dennis Cote

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to