I am busy learning Yii2, looking at this guide:
Yii documentation
In my customer table I have a field: customer_birthday which is of type: Date
Trying this code:
public function getBirthdayText()
{
return date('d/m/Y', $this->customer_birthday);
}
Running my page, getting this error:
A non well formed numeric value encountered on the line:
return date('d/m/Y', $this->customer_birthday);
Why do I get this error?
Yii 2 comes with very useful Formatter, which you can use to format your date.
Link: http://www.yiiframework.com/doc-2.0/yii-i18n-formatter.html#asDate()-detail
You should first properly configure formatter: http://www.yiiframework.com/doc-2.0/guide-output-formatting.html#configuring-formatter
And then format your dates in your needs: http://www.yiiframework.com/doc-2.0/guide-output-formatting.html#date-and-time
Related
Does anyone know why I am encountering this error with the most basic operation in PowerBI? After a few tries myself only ending in errors I copied the syntax straight off MS site and still......error.
I created a new table and used the following:
Table = calendar(date(2000,1,1),date(2030,12,31))
Error received:
Too few arguments were passed to the DATE function. The minimum
argument count for the function is 3.
When adding the arguments its as if the DATE function does not recognize the year value at all.
Anyone else encountering this?
Also, I noticed a lot of search results advising to use the "Modelling" tab which I don't have in my desktop version. I am currently still on a free trial.
Does a free trial mean I can not use the most basic DATE() function - I truly hope this is not the case.
I'm struggling with Laravel date formats, using it with PgSQL.
My need :
input date must be in this ISO8601 format: Y-m-d\TH:i:s\Z (example: 2016-05-13T10:05:00Z)
output must be in the same format
PgSQL stores it in the format Y-m-d H:i:s (example: 2016-05-13 10:05:00)
The hard part is to configure Laravel to globally accept a particular date format in input and output, but without changing "internal" format.
A property can be overridden to customize format, but it acts globally:
protected $dateFormat = 'Y-m-d\TH:i:s\Z';
This leads to errors when retrieving dates from database (trying to convert a PgSQL date with a custom mask: InvalidArgumentException).
I would like to avoid using a Middleware or do it manually in each controller response, is there any way?
Sounds like you want to use accessors and mutators. Here's a basic example with a class that has a my_date column, the conversion might not be exactly right (I'm just assuming strtotime() will work) but that should be easy for you to fix.
class SomeModel extends Model
{
// triggered whenever you retrieve the date from the db
public function getMyDateAttribute($value)
{
return date('Y-m-d\TH:i:s\Z', strtotime($value));
}
// triggered whenever you insert the date into the db
public function setMyDateAttribute($value)
{
$this->attributes['my_date'] = date('Y-m-d H:i:s', strtotime($value));
}
}
Now, your database can use one datetime format and the other parts of your application can use another. If you want it to be reusable for other models, you can extract it to a trait as long as the columns are named the same.
I am using Google Script to export some calendar events to a spreadsheet; the relevant portion of my script is below:
var details=[[mycal,events[i].getTitle(), events[i].getDescription(), events[i].getLocation(), events[i].getStartTime(), myformula_placeholder, ('')]];
var range=sheet.getRange(row,1,1,7);
range.setValues(details);
This code works but the "time" that is put into the spreadsheet is a real number of the form nnnnn.nn. On the spreadsheet itself the date looks great using the integer to the left of the decimal (eg 10/15/2017) but the decimals are part of the value and therefore are part of the spreadsheet value.
My script drops the data into a sheet in my workbook, and another sheet reads the rows of data with the above date types, looking for specific date info from the other sheet using the match function (for today()). That would work fine if I could get rid of the decimals.
How can I use what I have above (if I stray far from what I have found works I will be redoing hours of work) but adding just what is needed to only put into the output spreadsheet the whole number portion so I have a pure date that will be found nicely by my match function using today()?
I have been digging, but errors abound in trying to put it all together. "Parse" looked like a good hope, but it failed as the validation did not like parse used within getStartTime. Maybe I used it in the wrong manner.
Help would be appreciated greatly.
According to the CalendarApp documentation, getStartTime() generates a Date object. You should be able to extract the date and time separately from the date object:
var eventStart = events[i].getStartTime(); // Returns date object
var startDate = eventStart.toDateString(); // Returns date portion as a string
var startTime = eventStart.toTimeString(); // Returns time portion as a string
You could then write one or both of these to your spreadsheet. See the w3schools Javascript Date Reference for more information:
http://www.w3schools.com/jsref/jsref_obj_date.asp
If you If you want to specify the string format, you can try formatDate in the Utilities service:
https://developers.google.com/apps-script/reference/utilities/utilities#formatdatedate-timezone-format
You could just use the Math.floor() function
http://www.w3schools.com/jsref/jsref_floor.asp
which will round the real number to an integer. Your line would then read:
var details=[[mycal,events[i].getTitle(), events[i].getDescription(), events[i].getLocation(), Math.floor(events[i].getStartTime()), myformula_placeholder, ('')]];
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 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.