CakePHP 3: I have a database field which is a DATE (not DATETIME nor TIMESTAMP)
When I display
echo $contact->date;
It will show something like 2014. 01. 06. 0:00. How to hide hours and minutes?
I tried
print $this->Time->format($contact->date, 'Y-m-d');
but I got 2014-0-6
How to get year-month-day?
rrd
Have you tried this?
echo $contact->date->format('Y-m-d');
add in App\Controller:
use Cake\I18n\Time;
Time::$defaultLocale = 'es-ES';
Time::setToStringFormat('YYYY-MM-dd');
You can directly print the date object in any custom date String format by using the inbuilt i18nFormat function.
$frozenDateObj->i18nFormat('dd-MMM-yyyy');
Use Datetime Format Syntax reference for more customization
If need all over the project with specific format you can use
boostrap.php
Cake\I18n\FrozenDate::setToStringFormat('yyyy-MM-dd');
echo date_format($contact->date, 'Y-m-d'); //php format
try
date('Y-m-d',strtotime($contact->date));
Related
I have an issue where I want to display only the hh.mm in da-DK from the NOW() function in AMPscript.
I have tried the following two options.
formatdate(Now(),"","HH.mm","da-DK")
This inputs only time but servertime, ex. 03.16
format(Systemdatetolocaldate(Now()),"","hh.mm")
Correct time but the whole string, ex. 12/10/2020 10:16:44 AM
Anyone with some pointers?
I've found a "quickfix" with the set of
SET #redeemedHour = datePart(Systemdatetolocaldate(Now()),"H")
SET #redeemedMinute = datePart(Systemdatetolocaldate(Now()),"minute")
and then concanate
I know for a Tree Definition of DataElementFolder, there is a DateFormat attribute, but the DataElement node doesn't have such an attribute.
<DataElements Type="MA.PressRelease.Article" Label="${C1:Data:MA.PressRelease.Article:Date}" Display="Auto">
This will show up looking like this.
It would be nice to have something like "Month day, Year" (Ex: May 4, 2017)
https://github.com/Orckestra/C1-CMS-Foundation/issues, open a new issue, starting with the Title "Feature Request:" make a clear explanation about the benefits and anything else that you think that would improve and wait for response.
No, as of the latest release the date format is hard-coded:
https://github.com/Orckestra/C1-CMS-Foundation/blob/dev/Composite/C1Console/Trees/DataFieldValueHelper.cs#L65
Per version 6.2 of C1 CMS you can control the label format for fields of type DateTime, decimal and int - thanks to your feature request.
Usage: Append a colon and then a format string to your label directive, for example:
<DataElements Type="MA.PressRelease.Article" Label="${C1:Data:MA.PressRelease.Article:Date:MMM d, yyyy}" Display="Auto">
The format string is the same you would use with .ToString() for the type of the field, ex "MMM d, yyyy" for dates, "F1" or "C" for decimals and ints.
(sorry my english) Hi.
With 5.0.1, the default short date format for locale "es" (in config.json) return this date format "10/01/2017"
With 5.1, the default short date format for locale "es" (in config.json) return this date format "10 ene. 2017".
I think is a coherent change. But I need keep working with the old format. So, where I must touch to get the old format in a entire new 5.1 qooxdoo project?
I mean, where this locale format is defined? I was trying found where but I can't.
Or any other solution.
thanks
This snippet works for us
this._localeManager = qx.locale.Manager.getInstance();
this._localeManager.addLocale("el", {
"cldr_date_format_short": "dd/MM/yyyy" // Override short date format for Greek
});
$value="Mar 10 2016 09:12:03:000AM";
return Carbon::createFromFormat('Y-m-d H:i:s.u0', $value);
Please will someone please tell me how to use Carbon to
convert this date to that format.
I'm getting:
InvalidArgumentException in Carbon.php line 425:
Unexpected data found.
Unexpected data found.
The separation symbol could not be found
Unexpected data found.
The format separator does not match
Trailing data
use carbon like
$value="Mar 10 2016 09:12:03:000AM";
return \Carbon\Carbon::parse($value)->format('Y-m-d H:i:s.u0');
For detail about how to carbon module used please visit on link Carbon Docs
In controller declare use Carbon\Carbon;
$value="Mar 10 2016 09:12:03:000AM";
return Carbon::parse($value);
$value="Mar 10 2016 09:12:03:000AM";
Carbon::parse($value)->format('Y-m-d H:i:s.u0');
Use parse method to instantiate the $value string as carbon object and then you can use any of the helper functions available in Carbon Library.
Refer to the given link :: http://carbon.nesbot.com/docs/#api-formatting.
I am trying to format an date received as 31/12/2012 to 2012-12-31.
I have used ::format and ::toServer, but I get 2012-31-12 instead of 2012-12-31.
How can I do it ?
Thank you!
Try this:
//via Time helper
echo $this->Time->format('Y-m-d', "31/12/2012");
//via CakeTime utility
echo CakeTime::format('Y-m-d', "31/12/2012");
From CakePHP 1.3 manual:
(...) format is a wrapper for the PHP date function.