I am taking date from datepicker and time from timepicker. I create a date object out of it and store it as milliseconds in db. I am using sqlite database. I want to retrieve records for a particular date from db. If I compare field stored as milliseconds directly it will include time of the day also. How should I go about this complete thing?
You can then compare times just as in your example
long time1 = System.currentTimeMillis();
long time2 = ...;
if (time2 < time1) {
Related
I'm using Apps Script and trying to extract data from AdminReports.UserUsageReport.get('all', 'the date') (to get classroom last interaction timestamps), but it always comes with records from another day. For example, if I extract from the 5th, the report brings the 6th together, until 7 o'clock in the morning.
The date parameter is a string and in the documentation says the following:
Represents the date the usage occurred. The timestamp is in the ISO
8601 format, yyyy-mm-dd. We recommend you use your account's time zone
for this.
But if the parameter is a string in yyyy-mm-dd format, how am I going to pass the date with the right time zone?
This code not work:
var myDate = new Date(2021,5,5);
var timezone = Session.getScriptTimeZone();
var date = Utilities.formatDate(myDate, timezone, 'yyyy-MM-dd');
var page = AdminReports.UserUsageReport.get('all', date);
How do I use the date correctly?
Thanks a lot.
If the report dates are UTC, then each may first be converted to JavaScript Date objects using
var myDate = new Date('report_date_string');
The second two lines of your code look like they should follow correctly in converting and formatting the Dates to strings in your local time zone.
I have this doubt on how to compare DB2 date, time fields with RPG date and time fields
If (Zpschdt < CurDat or (ZPschdt = Curdat and
(%Time() - ZPschtm) > 30));
For example in the above piece of code, Curdat is a character field which contains date value populated using below line
CurDat = %CHAR(%DATE():*MDY);
%Time() that is the current time needs to be subtracted from ZPschtm which is a DB2 time field and needs to be checked if the difference is greater that 30 minutes. How can this be achieved?
You can't compare a character variable to a date variable.
Generally, you have to either convert the character to date, or the date to character.
Since you character variable is formatted *MDY, it'd be easier to convert it to date; otherwise you'd need to change the format to YYYYMMDD in order to compare it as a numeric or character.
If Zpschdt < %Date(CurDat:*MDY)...
If you want to find schedule dates and times that are more than 30 minutes old, and the timeframe needs to cross days, you are going to have to use timestamps rather than dates and times. To deal with your situation, define a timestamp field, assign the schedule date and time, add 30 minutes to the timestamp, and compare that to the current timestamp. Like this:
dcl-s ts Timestamp;
ts = zschdt + zschtm + %minutes(30);
if ts < %timestamp();
// do something here
endif;
Think I have found a good enough solution for this as below:
If ( %Diff(%Date():Zpschdt:*Days) > 1 or
(%Diff(%Date():Zpschdt:*Days) = 0 and
%Diff(%Time():ZPschtm:*Minutes) > 30));
The first condition of Or - %Diff(%Date():Zpschdt:*Days) > 1 checks if Current date is ahead of the change date at least by one day.
The Second condition :
(%Diff(%Date():Zpschdt:*Days) = 0 and
%Diff(%Time():ZPschtm:*Minutes) > 30))
checks if the Change date is same as current day and if Current time is ahead of change time by at least 30 minutes..
Does this look good enough? Seems to do the job..
So I am trying to make a timesheeting app in meteor, creating projects and adding time entries. Why? it was all I could think of as a test app.
But, I'm more used to dealing with PHP, in PHP I would just store a date field with a time length. Right now, I'm wondering what's the best wat to deal with dates in Meteor.
Do… I do the same thing where I store a parsed string of the date, or is it a date time object? How would you deal with dates? (I'm only 3 hours into Meteor)
Meteor also includes the momentjs library which makes dealing with dates and times very easy. You get function to format and parse.
The best way to store your time is in a Date object. This is because in Mongo you will get the timestamp and its GMT deviation. Making the time TimeZone secure.
In order to manipulate and display times, use momentjs.
This community hackpad with recommended methods and packages for storing and using dates is pretty useful:
https://meteor.hackpad.com/Meteor-Cookbook-Using-Dates-and-Times-qSQCGFc06gH
The best way to represent dates on your collection documents is by directly using the Date object type. You can store Date objects directly into collection documents. If we are creating a document, we can generate a Date object as one of the properties supplied to the collection's insert() method.
I would suggest that you store the time in epoch. It will make it a lot easier to sort and search. Normally getTime() gets the time since the epoch in miliseconds but you can divide by 1000 to get the time in seconds.1
var d = new Date();
var seconds = d.getTime() / 1000;
To convert to the local date if you need it you can just
var d = new Date(0); // The 0 there is the key, which sets the date to the epoch
d.setUTCSeconds(seconds);
I need to store date in mysql (without time). User inputs date in input box like yyyy-mm-dd, may be later fomat could change.
Could you please tell what is good way to store date in mongodb (without time), we'd use DATE type in mysql? Now whe I need to store date and time I use mongdb date type.
And store it like this:
$data['ADDED'] = new MongoDate(time());
And display them:
echo gmdate('Y-m-d H:i:s', $data['ADDED']->sec);
When I use only date I store them as string like: yyyy-mm-dd (I validate date before storing it to make sure it's correct date). I'll need to find by date something like this:
dateField <(>) somedate
Do you think it's acceptable to store date as string in mongodb? How do you usually store date in mongodb?
MongoDB does not have a DATE type. It instead has a ISODate type. This is just as good for storing "without" time as I will explain.
So you can use MongoDate like so:
$date = new MongoDate(); // Denotes today, just like the date() function
Now to store without time you can just fake it by making PHP only set a date, as such the default time will be 00:00:00 (I should note this does mean a time is actually stored just as 00:00:00):
$date = new MongoDate(strtotime('2012-04-23')); // strtotime for fun
And then you can query by just the date part like:
find(array('date' => new MongoDate(strtotime('2012-04-23'))));
And you can now query as though you don't have a time since the time will equal what you put in: 00:00:00.
Of course this is just one way of fixing it.
I'm currently trying to do it that way:
// Creating date object
$date = new Zend_Date();
// Adding to it 4 weeks
$date->add('4', Zend_Date::WEEK); // it's expire day
// Getting date in integer(i guess it's unix timestamp yes?)
$date->get();
// Saving it to Mysql in field 'expire' with type Varchar
Then, when needed to get rows, that have date bigger(that haven't yet expired), than current I just add to SQL a simple statement WHERE expire >= $current_date.
Or there is better way to do it? Or how it happens usually?
I would recommend using the native MySQL DATETIME column in your table. This is how you'd retrieve the date for MySQL:
$date->get('yyyy-MM-dd HH:mm:ss');