React Native Timestamp query (firestore) not giving the right result - reactjs

I have an query sorting by timestamp,
and I need to see only the data within last week
so I did
.dbRef
.where('regTime', '>', new Date( -7 * 24 * 60 * 60 * 1000)
but somehow not filtered by correct results.
anyone knows why?

seem to be less interesting / active programmers or people who like to help in react native,
so for future searchers:
let weekAgo = new Date();
let weekInMilliseconds = -7 * 24 * 60 * 60 * 1000;
weekAgo.setTime(weekAgo.getTime() + weekInMilliseconds);

Related

React - getting error when filter array of dates

This gives me a array of createdAt timestamps like: ['2022-05-22T21:57:45.202Z', '2022-05-22T21:57:45.205Z']
const unpaid = feeStatus.map((date) => {
return date.createdAt;
});
Now i wanna try to filter the array and show only those dates that are older than 14 days:
unpaid.filter(
(test) => new Date().getTime() - test.getTime() / (1000 * 60 * 60 * 24) > 14
);
But im getting this error: Uncaught TypeError: test.getTime is not a function
First of all, the getTime() function is a method of the Date object. So you will need to convert the strings to valid Date objects. e.g. new Date(str), or using a library to handle it, like date-fns.
Secondly, there is a group of brackets missing from your formula. It should be:
(new Date().getTime() - new Date(test)) / (1000 * 60 * 60 * 24) > 14.
References:
Date: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
Precedence: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#table
You need to cast a string format date to Date to be able to use its prototype methods:
unpaid.filter(
(test) => new Date().getTime() - new Date(test).getTime() / (1000 * 60 * 60 * 24) > 14
);

Monthly Auto Loan Payment Amount

I am trying to calculate an auto loan monthly payment amount of the front end using angularJS. My calcualtions are as follow and im not getting the right amount, the Results are returning 4
$scope.model.autoLoan.borrowAmount = 15000
$scope.model.autoLoan.interestRate = 3.25
$scope.model.autoLoan.loanLength = 60
var monthlyPayment = $scope.model.autoLoan.borrowAmount *
(($scope.model.autoLoan.interestRate / 12) *
(Math.pow((1 + ($scope.model.autoLoan.interestRate / 12)), $scope.model.autoLoan.loanLength))) /
(Math.pow((1 + ($scope.model.autoLoan.interestRate / 12)), $scope.model.autoLoan.loanLength) - 1);
console.log(monthlyPayment);
the console returns: 4062.502309286213 which should be retrunging something like 47.00. Not sure what I'm doing wrong here.

get the difference between 2 date & time by hours, minutes and seconds using cakephp

I'm trying to get the difference between a datetime and a current datetime using cakephp . I succeeded to get it but I want to convert it to only hours ,minutes and seconds .
here is my code :
$currDateTime = Time::now();
$date1 = $plan->start_day->format('Y-m-d');
$date2 = $currDateTime->format('Y-m-d');
$diff = abs(strtotime($date1) - strtotime($date2));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24)) ;
$time1 = $plan->start_day->format('H:i:s');
$time2 = $currDateTime->format('H:i:s');
$seconds = abs(strtotime($time1) - strtotime($time2));
$hours = floor($seconds / 3600);
$mins = floor(($seconds - ($hours*3600)) / 60);
$secs = floor($seconds % 60);
the result is a difference in years, months, days, hours, minutes and seconds.
how can I convert it to only H:m:s ??
There's no need for all these calculations, simply create a DateInterval diff using the diff() method provided by the time object, and use the days, h, i, and s values it provides to create your desired output. The only calculation that would be required, would be to add the days in hours.
$diff = $currDateTime->diff($plan->start_day);
$formatted = sprintf('%02d:%02d:%02d', ($diff->days * 24) + $diff->h, $diff->i, $diff->s);
See also
PHP Manual > Date/Time > DateTimeInterface > DateTimeInterface::diff
PHP Manual > Date/Time > DateInterval

How to Get time 2 Hours from current time in IONIC

I need to book a vehicle.So i get date.BUt i didnt got the time.Actually i want to book at least 2 hours after current time.also i need to get full time from next day onwards please help me.Iam doing in Ionic framework and AngularJS
Thanks in Advance
var timeNow = new Date().getTime();
var twoHoursIntoFuture = new Date(time + 1000 * 60 * 60 * 2);
the new Date() creates a new date object from current time. getTime() gets the time in milliseconds since January 1st, 1970. Then we just add 2 hours into timeNow (1000 * 60 * 60 * 2 milliseconds) and make a new date object based on that.
Check http://www.w3schools.com/jsref/jsref_obj_date.asp for more date manipulation info.
this.myActualDate = new Date(new Date().getTime() + (3 * 24 * 60 * 60 * 1000)).toISOString().toString().substring(0, 10);
this.myMaxDate = new Date(new Date().getTime() + (368 * 24 * 60 * 60 * 1000)).toISOString();
<ion-datetime displayFormat="YYYY/MM/DD" pickerFormat="YYYY MMMM DDDD" min={{myActualDate}} max={{myMaxDate}} [(ngModel)]="myActualDate"
formControlName="booking_date" class="flex-date" required></ion-datetime>
You can modify this code to perform yours.
If you want to extend three days in actual date then you can edit 365 digit into 368.
It will add three days in your date.
I think it will also work for time.
If you edit hours , minutes and seconds.

How to display Total Time Duration and Current Time of video

I want to display time duration of a video in silverlight 3.0 application. The format should be like 00:20 / 05:00 . ( Current Video time / Total Video Time). How to get it??.
TimeSpan _duration = mediaElement.NaturalDuration.TimeSpan;
var totalTime = string.Format("{0:00}:{1:00}", (_duration.Hours * 60) + _duration.Minutes, _duration.Seconds);
TimeSpan remaining = _duration.Subtract(mediaElement.Position);
var currentTime = string.Format("{0:00}:{1:00}", (remaining.Hours * 60) + remaining.Minutes, remaining.Seconds);
string result = string.formar("{0}/{1}",totalTime,currentTime);
Try this, Hope this can help.
Regards.

Resources