How to increment moths form 6 month? - laravel-5

i am making maintenance system. user can pay 6 months maintenance and there are two part first 6 months and last 6 month if user can pay for first 6 month then it can increment by 6 months and so on
if($request->session()->has('email')){
$abc=(Session::get('email'));
$users=Carbon::create(2019,0,30)->addMonths(6);
$check=$users->toDatestring();
}
if(Maintenance::where(['email', '=', $abc,'maintenance_status', '=', 'PAID'])){
$check= $users->addMonths(6);
$check=$users->toDatestring();
}
return view('maintenance',['check'=>$check],['abc'=>$abc]);
i expect to increment from 6 6 months but it can gives second increment not step by step like 2019-1-1 add 6 moths 2019-6-30 and if user can pay first part of maintenance then only increment by 6 months and so..

Use Carbon:
You need to import the namespace for Carbon
use Carbon\Carbon;
$articles=Article::where("created_at",">", Carbon::now()->subMonths(6))->get();
Apply this logic to your scenario.

Related

Years of Service Anniversary formula - Cognos Analytics - Costpoint 8.0.0

this one has been bugging me for a few weeks... I'm trying to write a formula in Cognos Analytics (costpoint) that returns if someone is hitting a new years of service milestone in the actual month.
returning a simple "true/false" or "yes/no" is perfect
essentially it's just if their years of service fall between multiple date ranges (ex: i want a return value of "yes" for someone currently at 4.95 years of service since they would hit their 5 years within the coming month)
years of service are in number format in column "A" in excel and in column [years of service] in costpoint (cognos) (ex: 9.154, 4.982, 24.995 ...)
i got an Excel version to work seen below:
=IF(OR(AND(A1>4.91,A1<=5),(AND(A1>9.91,A1<=10)),(AND(A1>14.91,A1<=15)),(AND(A1>19.91,A1<=20)),(AND(A1>24.91,A1<=25)),(AND(A1>29.91,A1<=30))),"yes","no")
i'm still just getting familiar with Cognos(costpoint) syntax, so i tried to write it as seen below:
if(or(and([Years of Service]>4.91,[Years of Service]<5),(and([Years of Service]>14.91,[Years of Service]<15)))then ('yes') else ('null')
without any luck...
anyone want to take a crack at it?? :)
In the absence of start dates, which would be easier, and handling the more general case (What if they are approaching 45 years of service?):
case
when MOD(MOD([Years Of Service], 5) + 1, 5) > 0.91
and MOD(MOD([Years Of Service], 5) + 1, 5) <= 1
then 'yes'
else 'no'
end
To see who reaches a "years of service" value that is a 5-year milestone next month, create a filter:
mod(
_months_between (
_first_of_month (
_add_months (current_date, 1)
),
_first_of_month ([StartDate])
),
60
) = 0
But if you have service start dates, you can use dates calculations to see who reaches a 5-year milestone next month:
mod(
_months_between (
_first_of_month (
_add_months (current_date, 1)
),
_first_of_month ([StartDate])
),
60
)
Look at the various case functions and try them for your expression.
I don't think you need a start date, you could just focus on the decimal portion of the Years of service field. You know that if the decimal portion is equal to or above ).9166 then the years of service is in the final month.
if ([YOS]-cast([YOS],integer)>=0.9166)
then
('Yes')
else
('No')
If you want to figure a major milestone year such as 5,10,15 then you can take the expression further.
if mod(
if ([YOS]-cast([YOS],integer)>=0.9166)
then
(cast([YOS],integer)+1)
else
(cast([YOS],integer)),5=0)
then ('Milestone Year')
else ('Keep on Working!')
Hopefully the above helps!

How to change month to year in dart?

I'm working on a flutter project and I want to change month to year? I have months and I want to get its year. for example, 16 months is equal to 1 years and 4 months.
If you are looking for exactly converting months to years and months, I don't think you need a library for that. It is just simple math
void main() {
var months = 16;
var year = (months / 12).floor();
var remainderMonths = months % 12;
print("$year year and $remainderMonths months");
}
And by the way, 16 months is 1 year and 4 months.

How to create CarbonPeriod without knowing end date?

I need help with CarbonPeriod. I'm creating reminder to take medicine from one date to another in hours interval like this:
$startDate = Carbon::parse($this->data->get('date'))->setTimezone($timezone);
$endDate = Carbon::parse($this->data->get('endDate'))->addDay()->setTimezone($timezone);
$interval = $this->data->get('interval');
$period = new DatePeriod($startDate, CarbonInterval::hours($interval), $endDate);
but now I need to create CarbonPeriod knowing only $startDate and $interval in days and not the $endDate. Like I want to take my tablet every day in 12 o'clock until I turn off this reminder myself. Can somebody help me with this?
Typically when doing this, I would simply set the end date a very long way in the future (10 years or 20 years or 30 years ... you get the idea) and also (if you think it will ever get close to that date) have a mechanism when checking the date to extend it when it gets close (i.e. a rolling end date as such).
You can do the following:
$date = Carbon::now();
$period = $date->toPeriod(null, 3, 'days');
$period->setRecurrences(INF);
This will create a never-ending period that jumps 3 days at a time.
Examples directly from the documentation:
CarbonPeriod::create('now', '2 days', INF); // infinite iteration
CarbonPeriod::create('now', '2 days', INF)->calculateEnd()->isEndOfTime(); // true
CarbonPeriod::create('now', CarbonInterval::days(-2), INF)->calculateEnd()->isStartOfTime(); // true
https://carbon.nesbot.com/docs/#api-period

Get a Specific WeekDay date after a date

I am trying to implement a delivery process that occurs at specific days of week for each region. So, in a Region that delivers on Tuesdays and Thursdays I need to be able to get next eligible date based on the date the product will be available. So, if I will have it read on the 5th, O need to get the date for the next Tuesday or Thursday.
I started implementing it on Carbon, but I and creating a lot of loops through dates, testing dates and checking if its valid. something of getting product availability date and checking each day after it if its a monday Tuesday or Thursday ... etc ///I am sure, using Carbon, will have a better way to do it.
Any hint on how to do that ?
Thanks for any help!
Define a date:
$date = Carbon::now();
Now you have to get the day:
$day = $date->dayOfWeekIso
If $date is monday, then you will get a integer and that would be 1. That is because: 1 (monday), 2 (Tuesday), ..., 7 (sunday).
Now that you have this number you just need to apply some simple logic.
If the number you get is a 2 (Tuesday) then you will need to add two days to your $date in order to get the delivery date:
$delivery_date = $date->addDays(2);
If your day is equal 4 (Thursday), then you need to add 6 days to your $date so that would give you the next Tuesday:
$delivery_date = $date->addDays(6);
I think that's what you want! I hope it helps!

Laravel, Carbon. Get count of hours for a specific month between dates

How to get the number of hours referring only to the one month between 2 dates?
For example, how to get count of hours for December for first or for second row at the screenshot?
I tried this (subMonths generated in the loop, so no worry about it):
$bookings = Booking::whereDate('departure_date', '>=', Carbon::now()->subMonths($i)->startOfMonth())
->orWhereDate('arrival_date', '<=', Carbon::now()->subMonths($i)->endOfMonth())->get();
and then:
foreach ($bookings as $book) {
echo Carbon::parse($book->departure_date.$book->departure_time)->diffInHours(Carbon::parse($book->arrival_date.$book->arrival_time));
}
But in this case I get count of hours for whole booking, how to get it only for December?
p.s. I need this for calculating the statistics (booking percentage).
You would likely need to ->addMonth() then go to the ->startOfMonth() then use diffInHours().
Carbon::parse($book->departure_date)
->addMonth()
->startOfMonth()
->diffInHours(Carbon::parse($book->arrival_date.$book->arrival_time));
I've omitted $book->departure_time otherwise the timestamp wouldn't be the first second of the first day of the month.

Resources