I am using laravel 4.1 with SQL Server 2008
I created a model based on Eloquent orm with timestamp:
class Attendance extends \Eloquent {
protected $table = 'Attendance';
public function users(){return $this->belongsToMany('User', 'Users_Attendance', 'user_id', 'attendance_id');}
}
When I try to insert new fields:
public function postAttendanceUsers() {
$attendance = new Attendance;
$attendance->user_id = Auth::user()->id;
$attendance->save();
}
Display the following error:
SQLSTATE[22007]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server] Conversion of a varchar data type to a datetime data type resulted in an out-of-range value. (SQL: insert into [Attendance] ([user_id], [updated_at], [created_at]) values (40, 2015-08-27 12:28:42.000, 2015-08-27 12:28:42.000))
I created a new method with the following format:
/**
* Get the format for database stored dates.
*
* @return string
*/
public function getDateFormat() {
return 'Y-d-m H:i:s';
}
I hope somebody be useful
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With