I’m having problems working with databases and files.
I want my app to remember the exact date it was first run on a computer.
So it can keep an exact record of how many days it’s been running on that computer.
What’s the best way to do it?
I just want to keep track of two properties: Year, and DayOfYear
I want to do that just for calculating and displaying statistics for the user,
but also I would like to know the safe way to use it for making time trial version apps.
Save this variable to a database or file as you wish
Upon subsequent runs, read your saved var., get a new date object to reflect the current time, and perform the necessary divisions to get hours, days, etc.
[quote=119123:@Radium Radiovich]The problem is I don’t know how to save the total elapsed seconds to a file or database,
and also how to update it after every run.[/quote]
Start by practicing with files and databases, and worry about recording first run when you know.
Don’t save the total elapsed seconds, just save the initial run’s totalSeconds then calc elapsed seconds when you need them. Trying to save elapsed secs. Every time is way too much work.
The others have given you good references on reading and writing files.
I noticed I can’t save a value with date datatype into the JSON file. it gives me an error.
How can I solve that?
Currently to MASK the problem, I proceeded to save any part of the date I needed as separate strings into the JSON.
like:
d.year
d.DayOfYear
d.month
etc…
[quote=120319:@Radium Radiovich]I noticed I can’t save a value with date datatype into the JSON file. it gives me an error.
How can I solve that?
Currently to MASK the problem, I proceeded to save any part of the date I needed as separate strings into the JSON.
like:
d.year
d.DayOfYear
d.month
etc…[/quote]
d.year, d.DayOftheYear and d.Month are all integers. You should record them as str(value) to make them strings before you add them to your Json.
Yes I know, I don’t have any problem saving those.
I meant how can I save the whole Date object directly into the JSON?
So later I can load it, and make use of any of its properties (d.year, d.shortdate, d.longdate, etc) that I like?
Is it possible to save the “date object” itself into a file or database?
[quote=120325:@Radium Radiovich]Yes I know, I don’t have any problem saving those.
I meant how can I save the whole Date object directly into the JSON?
So later I can load it, and make use of any of its properties (d.year, d.shortdate, d.longdate, etc) that I like?
Is it possible to save the “date object” itself into a file or database?[/quote]
Saving the TotalSeconds value and then after reloading assigning it to date.Totalseconds, as I posted above, sets the date object to the date you saved it. The Date object uses TotalSeconds as the core of its data ; all properties are derived from it.