Hey please pay attention to solve this problem I know this could be possible but I am not getting the way ..
I am using sqlite in android to store and manipulate the field as shown below in the figure
Figure http://s16.postimage.org/idc13pxdh/image.png
first_start_time,last_start_time,last_end_time are datetime field in SQLite database
I need to get the difference of last_start_time and last_end_time as mean of function so that I don't need to do it programatically
last_end_time = strftime('%Y-%m-%d %H:%M:%S','now','localtime')
last_start_time= strftime('%Y-%m-%d %H:%M:%S','2012-01-27 02:34:56')
,i,e if my firsttime is =2012-06-15 14:54:33
and Endtime is =2012-06-15 14:54:40
then time diff would be like this =00:00:14;
i want to have such difference time like last_end_time -last_start_time
i also want to use trigger to do use in sqlite data base in android
at the last I need that all my total_expended_time should get summed up like ...
select sum(total_expended_time) from study_result
.. one thing keep in mind the result should be in datetime stamp so that i can reflect it to my UI
Any suggestion will be appreciated
Related
i am trying to use compareTo method based on firebase docs to get how long ago was the database entry created.
https://firebase.google.com/docs/reference/android/com/google/firebase/Timestamp
I am trying to do something like this
var postedAgo = myEntry.dateCreated.compareTo(firebase.database.ServerValue.TIMESTAMP);
myEntry.dateCreated is stored TIMESTAMP, so all i got in my db is numerical value. I hope thats right. But the problem is when i log this it says that compareTo is not a function.
I am obviously doing something wrong, but i cant find almost anything on compareTo beyond the documentation. I wonder if anyone is even using it.
Thanks
Luke
The Firebase Database ServerValue.TIMESTAMP is not an actual value of a timestamp, but a so-called marker value that the server recognized (and then replaces by the current timestamp when writing to the database). Because of this, you cannot use ServerValue.TIMESTAMP in pure client-side operations.
If you want to determine how long ago a node was created, you'd take the timestamp from that node and subtract it from the current timestamp. So if myEntry.dateCreated is a timestamp that was written with ServerValue.TIMESTAMP, you could do:
System.currentTimeMillis() - myEntry.dateCreated
I am new at Android and also at StackOverflow as a registered user. I have been using this site a lot, but this is the first time that I need help and I could not find an answer.
I need to show in a ListView the diference in days between today and the date picked from a datepicker. I have the data in a SQLite data base. Where should I do the maths for this? In my CursorAdapter Class, or in the Cursor?
Because I need to change the color of the text if the expiration date for doing something is less than 2 days for instance. And that is why I need to do this on my listView to show the user which activities are close to be expired.
I will really appreciate any help. Thanks in advance!
Gretel
Let Sqlite do the math for you by calculating the date difference directly in the database query.
Something like this:
SELECT myNameCol as name, julianday('now') - julianday(myDateColumn) as dayDiff FROM MyTable;
The returned value for dayDiffis the difference in days from now and the value in the myDateColumn column.
I am trying to store a Person object with ActiveAndroid. I set the birthdate like this: person.setBirthdate(new java.sql.Date((new Date()).getTime()));. After assigning all data i am calling person.save();.
I get a list of all persons from the database with this command: new Select().from(Person.class).execute();
If I do not close the app everything works fine (birthdate is always returned correctly from the database). However, when I close the app completely and then restart it, the birthdate is always null. All other fields (first name, last name etc.) are correct.
I really don't know why this is happening and would appreciate some help!
EDIT: After taking a closer look at my database I found out that the birthdate-column is not created. I am still not sure why the data is available when not closing the app though.
Second EDIT: I added a new column (a string) which is saved to the database and works just fine. So the problem is not an outdated database. All columns but the date column get created.
I also changed the date datatype to a string. The birthdate was then saved. Changing it back to a Date datatype resulted in the original problem again. Really weird... Does anyone know whats going on?
It should be some caching problem.
for saving Date try to use type serializer. it is so easy just read this page.
I am building a monopoly game and from what I'm doing I'm almost done, but I want the game to end after 30dice rolls. But the way I want to do it is weird. I need a way to store data and check if the data is upto 30 or not, I mean check the amount of data is a row, I've been looking if sqlite or shared preferences would do, but can't get anything. Any idea would be welcomed and if you can help review my code too, I wouldn't mind. Thank You.
If you realy want to persist it in the Database, you want to have a key-value table current_game_progress with an item dice_rolls and update this each dice roll.
UPDATE current_game_progress SET content = content + 1 WHERE keyname = "dice_rolls"
But its a bit overhead. Maybe you want to store it local in a variable and transfer it on "save" action to the database.
Is there a way in android app that we can add some text or image and we can change that dynamically without adding new version. Like we have this text: Today's deal is: 1
then in a week if i want that text to show as: Today's deal is: 2.
Is there a way to do this, for an app which does not have a server and is stand alone app.
A text or image can be altered during run time; so how you choose to change that is up to you. You would have a simply switch statement depending on the day of the week for your specific example.
TextView tv = (TextView) findViewById(R.yourxml.name);
tv.setText("Monday!");
...
One way I can think of to achieve this is by writing a long value in the shared preferences for a Date object. Each time you start the application we will check if it's been 1 day since the value was saved. Also maintain the different string you want to display as string array in the resources.
I hope it helps...