Manipulating data from sqlite database - sqlite

Am a beginner in android development and i am designing an android app which takes input of a date and stores it in sqlite database. Could you please explain how i can retrieve the date and use it to calculate other dates which i will display in another activity
Eg if input is 1/1/2019, i need to calculate events that occur after this date and display them in order of events and the date
Event 1 - 12/01/2019
Event 2 - 2/02/2019
Event 3 - 26/02/2019
Event 1 occurs after like 21 days, event 2 occurs after like 24 days
How should i perform this calculation and display them in another activity?

The link mentioned above is correct. To put it simply just use SQLite's date function - it can calculate dates quite easily:
SELECT date('2019-01-12', '+21 days');
gives you 2019-02-02.
Instead of the date value use a column name of your table if approbiate.
Take the calculated date for the second event and add 24 days and SQLite gives you the date for the third event.
SELECT date('2019-02-02', '+24 days');
2019-02-26
Hint: my answer only deals with the database side (cause that's what your question is tagged with). I have no idea about the Android programming.

Related

In Data Studio Filter Data to < Current Hour

I do a lot of day-of reporting and one of the things I'm trying to do is compare today's performance to another day. The trouble is I'm trying to comp. to that day to the last full hour. Essentially filter out all data in that comp day that happened after the last completed hour.
I've accomplished this in Tableau but I'd like for this report to be done in Data Studio. Is there a way of using functions to create a custom metric that returns the current hour? If I could get that I could easily use it as a filter for my report.
Thanks for any help.
Here's what the solution looks like in tableau:
IF [Session Hour (int)] <= [Current Hour]
THEN
[Revenue GA]
END
And:
DATEPART('hour', Now())-4
I was able to filter to the current hour by
a) making a calculated field to figure out the minutes difference between now and the data
minutes_before_now = datetime_diff(current_datetime(),the_time,MINUTE)
and b) filtering the data where this field was < 60
My advice would be to create a filter inside a date range, p.e.
And then you can choose the comparison range within the primary date range.
That's what I'd do, if I understood your question.

fullcalendar wrong timespamp for midnight

I am using fullcalendar.io and I realized that if I create a new event in the month view, dragging across one or more days, it returns a timestamp for the end date which is later rendered as 12 am of the day after while it should be logic that a function date("what-ever-format", timestamp) returns 12 pm of the current day, or, in any case, not the following day.
Any idea how to fix this???

sum over date range in report (not query)

In Access 2010, I have a little form prior to a report which asks the user for a date range (e.g. 7.7.2015 - 9.9.2015). I pass this date range to the report as filter. The query contains the fields ActDate, Activity and Hours. I now want the report to look like:
Activities from <startDate> to <endDate>:
Activity Total Hours
Reading 5
Writing 8
Talking 3
What I'm getting is
Activities from <startDate> to <endDate>:
Activity Total Hours
Reading 2
Reading 3
Writing 1
Writing 3
Writing 4
Talking 1
Talking 2
The report should sum up equal activities over the selected date range and not display a separate line for each activity which just occured on a different date. Adding a group in the report for activities is no solution (it just adds extra blank lines).
I guess it's possible to build a custom query after the user dialog (in the query I could filter by date range and GROUP BY Activity), but it would be much simpler if the grouping could be done in the report without changing the query. Do I really have to change the query?

AppInventor: how to insert DateTime into Google Spreadsheet and show only recent DateTime

I am new to this forum so I hope I asking my question in the right place.
I have a problem inserting a datetime into a Google Spreadsheet from a form created in Appinventor2;
In app inventor2 I created a form that fills in a google spreadsheet. Basically I merged the Pizza Party example (http://appinventor.mit.edu/explore/ai2/pizzaparty.html) with this example http://puravidaapps.com/spreadsheet.php to use google spreadsheet instead of fusion table.
the user selects in how many minutes he wants his order and then sees all the orders in a table sorted by delivery time.
Problem A)
Firstly, i want to save the current datetime + the desired delay into the google spreadsheet and sort the table by this new datetime.
1) when i use the block "call clock format time" + "call clock addminutes" the spreadsheet is populated with a text, but then i can't sort the table by delivery datetime. in fact i believe the sorting is done on the number regardless of the am/pm or day of the month. so for example instead of having 4am, 6am, 2pm, 3pm i get : 2pm, 3pm, 4am, 6am.
2) I then tried to remove the block "call clock format time" and in the google form i kept the field format = text
but the google spreadsheet is populated with the following:
java.util.GregorianCalendar[time=1395531335908,areFieldsSet=true,lenient=true,zone=Europe/Dublin,firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2014,MONTH=2,WEEK_OF_YEAR=12,WEEK_OF_MONTH=4,DAY_OF_MONTH=22,DAY_OF_YEAR=81,DAY_OF_WEEK=7,DAY_OF_WEEK_IN_MONTH=4,AM_PM=1,HOUR=11,HOUR_OF_DAY=23,MINUTE=35,SECOND=35,MILLISECOND=908,ZONE_OFFSET=0,DST_OFFSET=0]
3) I then tried to remove the block "call clock format time" and in the google form I changed the field format = time
but then the google spreadsheet isn't populated with anything.
4)I tried using the segment block, but after a while I realised the block "format time" actually returns this format: "hh:mm:ss AM/PM"
so selecting the 5 characters is not good enough because it does not take into account of the am/pm element as well as the day of the month.
5) I found a temp solution by defining the desired delivery time as a new global variable, and extracting a string in the format hh:mm by joining the blocks ".hour instant" and ".minute instant".
However this is not a final solution because what i extracted is of course a string of text and when sorting, 01:10 will be always considered smaller than 23:50 for example, regardless of the date.
So is there a way of actually saving in the google spreadsheet not a string of text, but actually the date and time?
Problem B)
Secondly, I would like to filter/show only the rows of the google spreadsheet have a delivery time expired by no more than 1 hour (as well as orders with delivery time in the future e.g. in 2 hours from now()).
I tried using some Google Visualization API Query Language commands, altering the url of the google spreadsheet (like WHERE "now() - Delivery Time < 60 mins)" (cannot remember the exact code I wrote) but unsucessfully.
Would anyone know how to filter my results?
thanks in advance
alterettore
So there's a few things to note.
If you're using Taifun's example as you mention, you'll notice that when you submit data to Google Spreadsheets using a form, the first column is always a timestamp, even if you're not submitting a date or time. Trying to send the current date/time is redundant - go ahead and make use of what Google provided.
Google Spreadsheets (and Excel) store Date/Time as a number. If you want to store a date in GS, the best way to do so is not formatted text, but by sending a number. Use AppInventor to calculate the number you need. For example, today (April 27) in GS is 41756. Noon today would be 41756.5
To generate this number, start with AI's Millisecond function. NOTE: Both GS and AI use milliseconds, but they have different 0 points, so you have to manipulate the result a bit. The formula I've used in AI in the past is this:
GS Date/Time = (Clock1.GetMillis(Clock1.Now) / 86400000) + 25569
Hope this helps!

Complex Gridview Edit

I have a gridview that displays data in a crosstab format. The hours for each day are displayed. Each day is actually a separate row in the underlying table, so a row in the grid represents seven underlying tables.
WeekEnding(sat) Project Category Sun Mon Tues Wed Thur Fri Sat
8/14/2010 Proj1 testing 1 2 2 3 2
I want to write custom code to update each day. I have to caclulate the date based on weekending date and day ( ex fri date == Weekending - 1 day) and make 7 different update statements - one for each day in the row.
Where can I do this? Would I use the Gridview ItemUpdating event(edit: I meant RowUpdating event)?
======================
I need to add code when they click the "Update" button but not sure what event that is.
Currently when they click edit i have a textbox that appears for each days hours
Use the RowDataBound since you aleady have all the information you need to do this, inside this event you can get the complete object information that is bound and use the findControl to update the columns

Resources