I am trying to create a chart using a SQL database, I am using the duration column(HH:mm:ss) and the People column(Names).
But ASP does not support Time values for charts .Is there any other approach to display a TIME value like "45:34:12" to a column chart?I am trying to achieve a result like the one below.
If it is not possible ,is it possible in SQL to convert all the column that contains the "HH:mm:ss" values to a new decimal hour's column ?
Use a number instead.
Like it could be 10.84 hours or 2567.5 minutes.
This should work, but is less beautiful than the HH:mm:ss format.
Related
I have a dataset file with a time variable in "seconds since 1981-01-01 00:00:00". What I need is to convert this time into calendar date (YYYY-MM-DD HH:mm:ss). I've seen a lot of different ways to do this for time since epoch (1970) (timestamp, calendar.timegm, etc) but I'm failing to do this with a different reference date.
One option is to simply add 347133600s (11 years) to each value in seconds. this will then allow you to simply use conversion as it would be from 1970-01-01.
Im working on a flight-logbook in sqlite.
The "flights"-table has the following structure:
CREATE TABLE flights (event_id INT PRIMARY KEY, date TEXT, offblock TEXT, onblock TEXT, duration TEXT;
My goal is to find a statement that i can insert into the "duration" column, so that I will have the flight duration there.
INSERT INTO flights VALUES (1, "2019-04-04", "12:00", "18:00", XXX);
The result of duration should be 06:00, like this:
SELECT duration from flights WHERE event_id = 1;
06:00
Can anyone give me a working hint how to do this in the easiest possible way?
Thanks a lot!
You can do it with strftime() and time() like this:
SELECT strftime('%H:%M', time(strftime('%s','18:00') - strftime('%s','12:00'), 'unixepoch'))
which results in:
06:00
What you want to do is pretty complex as you have a string which represents time, which there isn't an explicit type for in sqlite. It's quite complicated, but it is possible and you could do the following:
-First remove the colon from the string: how to remove characters from a string in sqlite3 database?
-Then convert this string to an int: Convert string to int inside WHERE clause of SQLITE statment
-You would need to do this for the hours and minutes separately, as ints are obviously 10 based and minutes are 60 based so you can't simply subtract them. You would do this via ths Substr(X,Y,Z) function: https://www.sqlite.org/lang_corefunc.html
-Then you would do arithmetic to subtract final - initial time for both the hours and minutes. https://www.w3resource.com/sqlite/arithmetic-operators.php
-Finally take the calculated hours, and minutes, and add a colon in between them (assuming you want the same format).
Like I said, it's kinda heavy.. but it is doable if this automation saves time in the long run. This should be enough to get you there.
I want store in my sqlite database date in format DD/MM/YYYY HH:MM-HH:MM there is any solution of this ? I found only that YYYY-MM-DDTHH:MM answer.
SQLite has no specal data type for dates.
You can store dates in any format you want, but if you want to use any of the built-in date functions, you have to use one of the supported date formats.
What you want to store is not a date (a point in time), but a time interval.
There is no built-in support for intervals; the best you can do is to store the start and the end of the interval in two separate columns.
Please note that storing a date and displaying a date are two different things.
It would be easier to compute the length of an interval when the two date values are stored in one of the numeric date formats.
I am working with SSRS 2008. I have a table in my report consisting a date/Time Column (DOB). I have a date/time parameter (MyDate) as well. I am trying to set a Filter on my data set like
FormatDateTime(Fields!DOB.Value,2)<=FormatDateTime(Parameters!MyDate.Value,2)
It doesn't filter my table correctly. But if I remove FormatDateTime function then it works fine. i want to understand whats the problem here.
FormatDateTime will return a string, so you're not comparing dates anymore but rather their string representations.
Comparing the dates 02-Feb-2012 and 10-Oct-2012 will give different results than comparing the strings 2/2/2012 and 10/10/2012.
As mentioned in the comment, it looks like you're just trying to remove the time portion from dates?
Something like this should work, i.e. converting the strings back to dates.
CDate(FormatDateTime(Fields!DOB.Value,2)) <= CDate(FormatDateTime(Parameters!MyDate.Value,2))
But this is just one suggestion, there are any number of ways of doing this.
I kind of assumed it was a string, so I compared it as a string, but not surprisingly it failed. I believe thats how it works in Mysql. I could be wrong as I haven't worked on it in a while. In either case, how can I check if dates are equal in SQLite? I will be using it in a WHERE clause.
SELECT a._id, b._id, b.start_date,a.event_name, b.start_time,
b.end_date, b.end_time, b.location FROM events_info b INNER JOIN events a ON
a._id=b.event_id WHERE b.start_time = '6:00';
(added space to make it easier to look at)
SQLite doesn't have a dedicated DATETIME type. Normally what people do is make sure they store the date as a formatted string that is consistent; for example, YYYY-MM-DD hh:mm:ss. If you do so, as long as you're consistent, then you can compare dates directly:
SELECT * FROM a WHERE q_date < '2013-01-01 00:00:00';
This works because even though the comparison is technically an alphabetical comparison and not a numeric one, dates in a consistent format like this sort alphabetically as well as numerically.
For such a schema, I would suggest storing dates in 24-hour format (the above example is midnight). Pad months, days, and hours with zeros. If your dates will span multiple timezones, store them all in UTC and do whatever conversion you need client-side to convert them to the local time zone.
Normally dates and times are stored all in one column. If you have to have them separated for whatever reason, just make sure you dates are all consistent and your times are all consistent. For example, dates should all be YYYY-MM-DD and times should all be hh:mm:ss.
The reason that YYYY-MM-DD hh:mm:ss is the preferred format is because when you go from the largest date interval (years) to the smallest (seconds), you can index and sort them very easily and with high performance.
SELECT * FROM a WHERE q_date = '2012-06-04 05:06:00';
would use the index to hone in on the date/time instead of having to do a full table scan. Or if they're in two separate rows:
SELECT * FROM a WHERE q_date = '2012-06-04' AND q_time = '05:06:00';
The key is to make sure that the dates and times are in a consistent format going into the database. For user-friendly presentation, do all conversion client-side, not in the database. (For example, convert '2012-06-04 05:06:00' to "1:06am Eastern 6/4/2012".)
If this doesn't answer question, could you please post the exact format that you're using to store your dates and times, and two example dates that you're trying to compare that aren't working the way you expect them to?
Sqlite can not compare dates directly. we need to convert them in seconds as well as integer also.
Example
SELECT * FROM Table
WHERE
CAST(strftime('%s', date_field) AS integer) <=CAST(strftime('%s', '2015-01-01') AS integer) ;
From Datatypes In SQLite Version 3:
1.2 Date and Time Datatype
SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:
TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.
Applications can chose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions.
If you look at the examples in Date And Time Functions, something like this should get you close to what you want (which, I'm assuming, is 6:00 of the current day):
WHERE b.start_time = date('now', 'start of day', '+6 hours')