I want to change the language of the date i get in my view from english to french
{{ strftime("%d %B %Y, %H:%M", strtotime($article->created_at)) }}
we can use another method with translatedFormat
Carbon::setLocale('fr');
echo $base_weight_category->created_at->translatedFormat('l jS F Y');
we can see result jeudi 2 avril 2020
Set Carbon locale first, then access
Carbon::setLocale('fr');
$date_to_show_in_view = $article->created_at->diffForHumans();
For your second query(to get 15 Mars 2018), use this-
<?php
setlocale(LC_TIME, 'French');
echo $base_weight_category->created_at->formatLocalized('%d %B %Y');
?>
Related
I am doing a credit collection app which offer loans to the borrowers. I've been stock in this for so many days now because I can't think of a better way to do it.
SO basically I want to achieve is to have a list of due dates which I will display in the borrower dashboard. for example, the borrower applied for a 2 months loan duration and bi-monthly payment scheme and let say the admin approve it today. So what I want is base from the date today, 12-10-2021 the system will generate 4 due dates(12-25-2021, 12-8-2021, 1-23-2022 and 02-7-2022) and will save them to a separate due dates table.
With regards to the payments, I can analyze the part where the system can check if the payment is done on or before the first due date but how can I tell to the system that the payment is advance payment for the next 3 due date?
what I only have right now is this
$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');
Which can identify the first due date.
Can you help to point to any resources out there than will help me achieve my objective? I am hoping I was able to describe the question and my objective clearly. Any suggestions will be very much appreciated. Thank you so much in advance!
RESPONSE FOR #GRANT
I am following your code
$date_approval = Carbon::createFromTimestamp(strtotime($loanapplication->date_approval));
$scheme_numdays = $loanapplication->scheme->num_days;
$days = (intdiv($date_approval->diff(Carbon::now())->days , $scheme_numdays) + 1) * $scheme_numdays;
$due_date = $date_approval->addDays($days)->format('Y-m-d');
$due_date_plus = $date_approval->addDays(60)->format('Y-m-d');
# Carbon Period usage:
$result = CarbonPeriod::create($due_date, $scheme_numdays.' days', $due_date_plus);
I replace the '# days' in the $result with $scheme_numdays so which contains the number of days.
Then I display it like this,
<div class="col-md-6">
{{$date_approval}}<br/>
{{$loanapplication->date_approval}}<br/>
#foreach ($result as $dt)
{{$dt->format("M d Y")}} <br/>
#endforeach
</div>
the result is
2022-02-27 00:00:00
2021-12-14
Dec 29 2021
Jan 13 2022
Jan 28 2022
Feb 12 2022
Feb 27 2022
Question:
why {{$date_approval}} (2022-02-27 00:00:00) and {{$loanapplication->date_approval}} (2021-12-14) gave different result? The date 2021-12-14 is what I have in my database.
My second question is why the result is five instead of 4 only?
The Data I'm displaying is, the loan duration is 60 days and the payment scheme is on every 15 days or fortnightly.
CarbonPeriod would be perfect for this particular scenario. Have you tried the following:
$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('Y-m-d');
$due_date_plus = $date_approval->addMonths(8)->format('Y-m-d');
# Carbon Period usage:
$result = CarbonPeriod::create($due_date, '2 months', $due_date_plus);
foreach ($result as $dt) {
echo $dt->format("M d Y");
}
You may need to namespace it:
use Carbon\CarbonPeriod;
Edited answer for followup questions:
<div class="col-md-6">
{{ $date_approval->format('M d Y') }}<br/>
{{ $loanapplication->date_approval->format('M d Y') }}<br/>
#foreach ($result as $dt)
#if($loop->index > 3)
#break
#endif
{{ $dt->format('M d Y') }}<br />
#endforeach
</div>
An alternative is date casting when getting dates from models.
(in loan application model):
protected $casts = [
'date_approval' => 'datetime:M d Y',
];
I want to change the date format to the Indonesian date format.
I have added code like this in app/Providers/AppSserviceProvider.php
public function boot()
{
config(['app.locale' => 'id']);
\Carbon\Carbon::setLocale('id');
}
and I call him a command like this:
\Carbon\Carbon::setLocale('id');
echo \Carbon\Carbon::now()->format('l, d F Y');
but it did not work well, the date format was not yet Indonesian. What is wrong ?
You can control timezone of your application in the timezone variable inside config/app.php file.
Don't foget to clear cache after: php artisan config:cache.
upd: try this:
setlocale(LC_ALL, 'IND');
echo \Carbon\Carbon::now()->formatLocalized('%A %d %B %Y');
Silakan dicoba kawan :
$date = Carbon::parse('2021-03-16 08:27:00')->locale('id');
$date->settings(['formatFunction' => 'translatedFormat']);
echo $date->format('l, j F Y ; h:i a'); // Selasa, 16 Maret 2021 ; 08:27 pagi
You can control timezone of your application in the timezone variable inside config/app.php file. Don't foget to clear cache after: php artisan config:clear.
and try this in app.php:
'timezone' => 'Asia/Jakarta'
then your carbon like this:
Carbon::now()->formatLocalized('%A, %d %B %Y')
in my blade there is a DateTime picker which selects in mm/dd/yyyy hh:mm AM/PM format. and i need to extract this to date = 8/29/2011 and time = 13:00 .
how can I do that?
Do as below.
$stringdate = "8/29/2011 1:00 PM";
$timestemp = strtotime($stringdate);
$date = date('Y-m-d', $timestemp);
$time = date('H:i:s',$timestemp);
echo $date;
echo $time;
check example
Edit:- as you want this format YYYY-MM-DD hh:mm
$datetime = date('Y-m-d H:i', strtotime("8/29/2011 1:00 PM"));
echo $datetime; //output "2011-08-29 13:00";
Try this way.
#php
$input = '2017-06-27 12:58:20';
$format1 = 'Y-m-d';
$format2 = 'H:i:s';
$date = Carbon\Carbon::parse($input)->format($format1);
$time = Carbon\Carbon::parse($input)->format($format2);
#endphp
It is simple just try it
$date="8/29/2011 1:00 PM"; // date that get from view (blade page)
$createTimestamp = new DateTime($date); // create timestamp object from string
$date = $createTimestamp->format('m/d/Y'); // get date
$time = $createTimestamp->format('H:i:s A'); // get time with AM/PM format
return "date: ".$date." time: ".$time; // return your result
Try this way
Use Carbon;
$dateAndTime=Carbon::parse('8/29/2011 1:00 PM');
$date=$dateAndTime->format('d-m-Y');// 29-8-2011
$time=$dateAndTime->format('H:i:s');// 1:00
$time=$dateAndTime->format('H:i:s A');// 1:00 AM/PM
Refer this link to understand more about Carbon.
The date format for my begin_date attribute is displaying like : 2015-04-25 00:00:00
and i want it like : 25 04 2015
I tried :
<?php
echo $this->helper('core')->formatDate(getbegin_date(), Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
?>
But it don't work.
Here is how you can format the time (in PHP). If you need more reference then check this page: Playing with Dates in Magento
$current_time = Mage::getModel('core/date')->timestamp(time());
echo $date = date('d m Y', $current_time);
I can get the current date&time by using
$today = JHTML::_('date', time(), '%Y-%m-%d %H:%M:%S');
echo $today;
How to I get 1year later and 1month later base on $today??
eg.now:2011-12-10 13:00:01
How to get 2012-12-10 13:00:01 AND 2012-01-10 13:00:01
It might not be the best way to do it, but this should work:
$time = mktime( date("H"), date("i"), date("s"), date("m")+1, date("d"), date("Y") + 1);
JHTML::_( 'date', $time, '%Y-%m-%d %H:%i:%s');
Alternatively, if you are using PHP 5.3, you can use the DateTime object.
I hope it helped!