PHP convert Variable holding a 24 hour time to 12 hour - time

I have a variable from the database
$time = $row['pu_eta']; //13:00
I now need to convert it to: 12 hour format.
Trying this has not succeeded. Any help would be most appreciated.
$time = format(strptime($time, format('%H:%M'), '%I:%M %p');

I found after extensive searching I was able to find a solution. I hope it's helpful to you too.
$row['pu_eta'] = "13:00";
$time = date_create($row['pu_eta']);
$time2 = date_format($time, "h:ia");
echo $time2; //01:00pm

Related

DAX number of days

Can you please help how I can return the total number of days for each month in a given quarter?
For example, I already have 92 days for December 2025 but how can I show 92 days for October and November as well?
If you want only a count, you can use measure:
QuarterDays = calculate(countrows(VALUES('Calendar'[Date])), FILTER(ALL('Calendar'), selectedvalue('Calendar'[Year]) = 'Calendar'[Year] && selectedvalue('Calendar'[Quarter]) = 'Calendar'[Quarter] ))

How to create a proper calculation of a due date in a dynamic manner in laravel

I been analyzing the proper calculation of the duedate for my app. I am working with a lending app where I need to display the due date for the borrower.
let say the approved date of their loan is 2019-10-27 and today is 11-5-2019. the payment scheme is dynamic. depending on what the admin set. in this example, the payment scheme weekly so I just need to say;
$duedate = date('M d Y', strtotime($loan_application->date_approval. ' + '.$loan_application->scheme->num_days.' days') );
from my example above the due date is supposedly on Nov 3, 2019. Now how can I make it say that the next due date is on Nov 10, 2019?
I really tried to analyze, here's my thought.
I get the difference between the approval date and NOW()
$diff = Carbon::createFromTimestamp(strtotime($loan_application->date_approval))->diff(Carbon::now())->days;
now I compared the $diff with $loan_application->scheme->num_days. so let say the $diff=9 and $loan_application->scheme->num_days = 7
now I created the condition
if ($diff > $loan_application->scheme->num_days) {
//should display
Nov 10, 2019
//because the current date is already Nov 5
}
and after Nov 10, + 7 days again, and + 7 days again and so on.
here is the complete code I already have;
$dateApproved = Carbon::parse($loan_application->date_approval)->toFormattedDateString();
$now = Carbon::today('M d Y');
$duedate = date('M d Y', strtotime($loan_application->date_approval. ' + '.$loan_application->scheme->num_days.' days') );
$diff = Carbon::createFromTimestamp(strtotime($loan_application->date_approval))->diff(Carbon::now())->days;
$numOfScheme = $loan_application->loanDuration->num_days / $loan_application->scheme->num_days;
if ($diff > $loan_application->scheme->num_days) {
}
I hope you understand my question. Please help. Thank you so much in advance.
this will add number of days from payment scheme. in my example 7 days. but how can I tell my code that today is already 2 days late, add additional 7 days
It took some time but I understood your question.
$date_approval = Carbon::createFromTimestamp(strtotime($loan_application->date_approval));
$scheme_numdays = $loan_application->scheme->num_days;
$days = (intdiv($date_approval->diff(Carbon::now())->days , $scheme_numdays) + 1) * $scheme_numdays
$due_date = $date_approval->addDays($days)->format('M d Y');
intdiv is just php's integer division.

ROR + Ruby Date Decrease by 15 minutes

If I have #time = Time.now.strftime("%Y-%m-%d %H:%M:%S"),
How can I reduce this time by 15 minutes ?
I already tried this one :: #reducetime = #time-15.minutes, works fine at console but give errors while execution. Other than this Is there any way to resolve this issue.
Thanks
Your problem is that you're formatting your time into a string before you're done treating it as a time. This would make more sense:
#time = Time.now
#reducetime = #time - 15.minutes
# And then later when you're reading to display #time...
formatted_time = #time.strftime("%Y-%m-%d %H:%M:%S")
You shouldn't format your data until right before you're ready to display it.
If you must have #time as the formatted time then you're going to have to parse it before computing #reducetime:
#reducetime = (DateTime.strptime(#time, "%Y-%m-%d %H:%M:%S") - 15.minutes).to_time

how to convert timestamp on windows ping -s option to date?

ping [SomeIP] -s 4 -t > ping.log
result of that command is like below.
Reply from [SomeIP] : bytes=32 time=4ms TTL=125
Timestamp: [HOP] : 83842793 ->
[HOP] : 83842793 ->
[HOP] : 83832797 ->
[HOP] : 83842793
how can i convert this timestamp to datetime?
The timestamp you get is number of miliseconds past midnight UTC time. Date is current date.
Conversion from here is simple:
time = timestamp /1000
hours = (time / 3600)
minutes = (time / 60) - (hours * 60)
seconds = time mod 60
If anyone is looking for a quick way to convert date/time to timestamp and back, I just came across this chrome extension and I think it's really great! It's the quickest cross platform method and I use it constantly since it parses plenty of date formats and is really fun nice to use.

smarty and date

i get date with: {$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'}
But how get 20 day after?
If now: 2010 05 05 12:12:12, I wish to show 2010 25 05 12:12:12
{$smarty.now} is a simple timestamp (number of seconds since 1970). So you can just add as many seconds to it as you need:
{$smarty.now+20*24*60*60|date_format:'%Y-%m-%d %H:%M:%S'} //+20 days
This works in Smarty3, if not in older versions then you might need to do the math with {assign} and/or {math} directives.
Use the strtotime() php function and assign your variable to smarty. Something like this:
<?php
$later = strtotime('+20 day');
$smarty->assign('later', $later);
?>
Then in the template:
{ $later|date_format:'%Y-%m-%d %H:%M:%S'}
You can use strtotime() directly as a modifier.
{"+20 days"|strtotime|date_format:"Y/m/d"}
In newer versions of smarty it will strtotime any string you prepend
I.e. instead of doing {$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'} you can also do {"now"|date_format:'%Y-%m-%d %H:%M:%S'}
To get the date 20 days from now, you can do:
{"+20 days"|date_format:"%Y-%m-%d"}
{assign var="iItemOne" value=$smarty.now}
{assign var="iItemTwo" value=1296000} //60*60*24*15-> for 15 days
{assign var="iSum" value=$iItemOne+$iItemTwo}
{$iSum|date_format:'%Y-%m-%d %H:%M:%S'}
Tested in smarty : Add 1 day ,2 days ......365 days in dynamic date.
$one= date("Y-m-d", strtotime(date("Y-m-d", strtotime('$add dynamic date variable')) . " + 1 day"));
$this->smarty->assign('one',$one);
$two= date("Y-m-d", strtotime(date("Y-m-d", strtotime('$add dynamic date variable')) . " + 2 day"));
$this->smarty->assign('two',$two);
...
..
$oneyear= date("Y-m-d", strtotime(date("Y-m-d", strtotime('$add dynamic date variable')) . " + 365 day"));
$this->smarty->assign('oneyear',$oneyear);

Resources