Laravel Make: Auth with SQL SERVER

1

Hi, I'm using Laravel 5.2. * with PHP 5.6+, everything is working as it should be when it comes to connections, use the Make:auth to create the login with Laravel, but at the time of registration (or ok using the register by default) gives me an error:

Error message:

  

[1/2] SQLSTATE [22007]: [Microsoft] [ODBC Driver 11 for SQL Server] [SQL   Server] The conversion of nvarchar data type into datetime produced a   value out of range.

     

[2/2] QueryException in Connection.php line 729: SQLSTATE [22007]:   [Microsoft] [ODBC Driver 11 for SQL Server] [SQL Server] Conversion   of the nvarchar data type in datetime produced a value outside of   interval. (SQL: insert into [users] ([name], [email], [password],   [updated_at], [created_at]) values (pruebabaname, [email protected],   and $ f3MSrI4.mgOu3ApY5jcQIeIG85Zj1SfGVGeG / 5mGBovY5bNA1LrLe, 2017-02-23   10: 38: 54,000, 2017-02-23 10: 38: 54,000))

I understand that the given error is due to the date format between what Laravel sends and what SQL SERVER receives, but the strange thing is that when doing the command insert into from new query, I get the same error, but when I insert the data directly in the table, it works ... as I could do so that:

1- Laravel send data according to SQL

or

2- The field of the table adapts to receive the data well.

    
asked by Maykol Rivas 23.02.2017 в 15:43
source

2 answers

2

As I referenced in my comment, you can change the format of the date by means of the property $dateFormat in the model:

class User extends Model
{
    /**
     * The storage format of the model's date columns.
     *
     * @var string
     */
    protected $dateFormat = 'M j Y h:i:s'; // o el formato que te sirva

    // ....
}
    
answered by 23.02.2017 / 19:04
source
0

The handling of date-type values is always annoying when one develops due to the different cultural formats that exist.

The first thing I recommend is to make sure that the type of data that you are going to send to SQL is a datetime not a string with a date format.

Now if what you are going to send to SQL is a string with date format, then always use the following format 'YYYYMMMDD hh:mm:ss' this will never fail you, for your example:

  • Do not send this: '2017-02-23 10:38:54.000'
  • Send this: '20170223 10:38:54'

By way of rehearsal simply put directly in your code the example that I am giving you and surely you will not present the error you are indicating.

    
answered by 23.02.2017 в 18:05