I researched everywhere but could not find the solution,
In the database, I am using from_date field as date(2018-07-07) type
But when I find the data then it auto converts in from_date to 'Cake\I18n\Date Object'
[from_date] => Cake\I18n\Date Object
(
[time] => 2018-07-07T00:00:00+00:00
[timezone] => UTC
[fixedNowTime] =>
)
I what this as
[from_date] => '2018-07-07'
I know we can covert this by
$obj->from_date->format('Y-M-D');
but the data is coming in an array of 10000 loops, this is not a good idea to convert in the loop.
I also tried this in bootstrap.php
Type::build('date')->useLocaleParser()->setLocaleFormat('y-m-d');
but this is also not working.
Please help
in your bootstrap.php you can set the default format you want when converting Date and FrozenDate to string in Json
see the manual here and the api here
note that you have to use string patterns described here and not the patterns you usually use with date()
so your code should be
\Cake\I18n\FrozenDate::setJsonEncodeFormat('yyyy-MM-dd');
\Cake\I18n\Date::setJsonEncodeFormat('yyyy-MM-dd');
Related
I need to set end_at attribute 30 days from current date. how can i do that in laravel 4.
When I have used bellow code I am getting error saying "Class 'Date' not found"
Please help me to fix this.
$sub->end_at = new Date('+30 days');
There is no Date class in PHP, there is only a DateTime class which you could use.
But since you're using Laravel, which uses the Carbon library by default, you can use that to handle dates because it has a better API. In your case you can do this:
use Carbon\Carbon;
...
$sub->end_at = Carbon::now()->addDays(30)->toIso8601String();
If you're trying to update a Eloquent model, then you can take advantage of Eloquent's integrated date/time column handling. In your model you can add the dates property with this value:
protected $dates = ['end_at'];
and now when assigning a timestamp to the end_at column, Laravel will automatically transform and save it to the correct format in your database. So you'll only need to use this:
$sub->end_at = Carbon::now()->addDays(30);
This will return that in the format appropriate for MySQL
$sub->end_at = date('Y-m-d H:i:s', strtotime('+30 days'));
I have used ${__time(dd-mm-yyyy)} function of Jmeter, i wanted to know if I can
manipulate this function that will return me the following convention "yyyy-mm-dd", I have tried ${__time(yyyy-mm-dd)} and I have noticed that I got the following date 2015-14-25 (for today: 01-25-2015) I did not understand why I got this date convention.
I managed to do it, Jmeter reference to case sensitive so in this case that would work: ${__time(yyyy-MM-dd)}. Jmeter would reference to 'MM' as the month.
I have Date data and converted to string "2014-04-16 08:27:52" from my local PostgreSQL.
Please explain me how to set it at Parse.com as Date datatype?
In the docs on rest API search on date and see the json type and format :
"__type":"Date","iso":"2011-08-21T18:02:52
That would be Included in the date elements json used in the post.
I just figured it out:
var date = new Date("2014-04-16 08:27:52");
object.set("last_update",date);
In PHP, you can do:
$parse->someDate = $parse->dataType( 'date', '1985-01-01' );
In JavaScript, you can do:
var someDate = new Date("1985-01-01");
yourclass.set( 'someDate', { "__type": "Date", "iso": someDate.toISOString() } );
For Parse.com and PHP, the answer is less straight forward than what is presented here. It took me a while to figure out that dataType() isn't working for some reason in the SDK.
It seems many people got the $parse->dataType() syntax from here. But I can't find this function anymore in the official SDK.
Then there is this bug and the resulting function from StackOverflow, but neither of these are very user friendly.
As it turns out, the Parse PHP SDK will handle an array for the value in the createdAt, updatedAt, and other special data types.
This code works (essentially a direct port from their REST API / JavaScript):
$query->greaterThanOrEqualTo("createdAt", ["__type" => "Date", "iso" => date('Y-m-01\TH:i:s')]);
Feel free to use that format for other special types, like GeoPoints.
Hi I need to check multiple dates for reminder section of my application.
But when I fetch dates from mongodb I am getting this:
DateTime Object
(
[date] => 2014-03-31 15:00:00
[timezone_type] => 3
[timezone] => Europe/Berlin
)
I am trying this to access date parameter but it is showing me error that dateTime object can not converted into string.
I am looping dateandtime.
Please let me know how can I access date in this situation in symfony.
Thanks
The assumption of others is that you recieve a MongoDate object back but you don't since I beleive Symfony actually converts it to a DateTime: http://www.php.net/manual/en/class.datetime.php (I think this comes from Doctrine 2)
What you can do is use the format function: http://www.php.net/manual/en/datetime.format.php like so:
$date->format('Y-M-d h:i:s')
You can do this in php (symphony is a php-framework).
All you need is something like this:
date('Y-M-d h:i:s', $yourDateTimeObject->sec);
You can also use __toString method from MongoDate class, but I actually prefer the previous method with sec.
I want to convert a datetime field into a numeric representation in form of YYYYMMDD. So, my logic here is (from 2011-01-01 12:00:00.000 to 20110101) :
convert(int, replace(cast(getdate() as date), '-', ''))
According to MSDN ( http://msdn.microsoft.com/en-us/library/bb630352.aspx ), the string representation is [always?] "YYYY-MM-DD", so I simply convert that string to an INT after removing dashes from the string.
Will this always works? Will I encounter some problems with that? Is there a better way to achieve this?
Thanks
That approach can work, not sure what would happen with localization settings. If you use the built in datetime conversion function options (http://msdn.microsoft.com/en-us/library/ms187928.aspx) you can avoid using the replace and not worry about locales.
Example:
select CAST(convert(varchar,getdate(),112) as int)