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.
Related
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!
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.
I want to set 10 years back date from today date in kendo datepicker.
If you want to initialize your date picker with 10 years back date always, then in your HTML it would be something like this:
#(Html.Kendo().DatePicker().Name("myDatePicker").Value(DateTime.Today.AddYears(-10)))
For an example: When we are working with any Bank form applications, the applicant should have minimum 20 years from Today's Date to apply a particular Exam.
So It's Better to give Max-Date as the Day 20 years from Today's Date
It is very easy to set past 'n' number of years date from today date in kendo datepicker.
Find the small snippet below.
var toDate = new Date();
// Here 'n' Excludes number of years from today's Date.
var pastDate= new Date(toDate.setFullYear(toDate.getFullYear()- n));
$("#birthDayDate").kendoDatePicker({
max: pastDate
});
I am having a problem about getting the month datedifference between two dates.
Here is a sample:
DateDiff("m","2014-10-17","2014-10-30")
The above code returns 0 months since it is less than a month. But,
DateDiff("m","2014-10-17","2014-11-01")
returns 1 which should not be since it is still 15 days.
My problem is I want to see if these two dates already exceed a month but it seems that it calculates 1 month only when the month part of the date is changed.
DateDiff calculates the span between two timestamps with the precision defined in the first parameter. From what you described in your question and comments you rather seem to be looking for something like this:
ds1 = "2014-10-17"
ds2 = "2014-10-30"
d1 = CDate(ds1)
d2 = CDate(ds2)
diff = DateDiff("m", d1, d2)
If diff > 0 And Day(d2) < Day(d1) Then diff = diff - 1
WScript.Echo diff & " full months have passed between " & ds1 & " and " & ds2 & "."
You can calculate day difference between two dates using 'DateDiff("d",date1,date2)'.
Then calculate number of full-month by dividing 30 days.
Following is an example.
monthDiff = int(DateDiff("d","2014-10-17","2014-11-01") / 30)
As you know, days of months differs by month. For example, November has 30 days and December has 31 days.
If you wish to use 30 days a month when first day is on November, and to use 31 days a month whe first day is on December, the code need a table of days of months and routine to handle month information.
I need to filter a record set like
OrderShippedDate - 20 days <-- Get all orders with a ShippedDate 20 days ago
var orders = ctx.Orders.Where(p => p.OrderShippedDate == 20) <---??? not sure what I need here .ToList();
How do I do a date diff in EF / LINQ?
I would suggest you work out your parameters locally, and then pass those in. It's not clear from your description whether you mean exactly 20 days ago, more than 20 days ago, or less than 20 days ago, which makes it hard to give you concrete advice, but if it's "more than 20 days ago" you might use something like:
var upperBound = DateTime.Today.AddDays(-20);
var orders = ctx.Orders.Where(p => p.OrderShippedDate < upperBound);