Date is not "blank" sql-srv

Asked

Viewed 1,299 times

3

I have a column in the type database date.

inserir a descrição da imagem aqui

When I change some date in a form php and leave blank the same instead of being blank she brings me this date of 1900-01-01.

Below the input I use to change the date.

Date Departure:

<input type="date" id="saida" name="saida" value="<?php echo $datasaida; ?>"/>

I believe it is the problem in the bank. Any idea?

  • 1

    Friend that if you set the field in the database with some type that corresponds to a date and you do not send a valid date, it will bring the default, which is not something null or white, in Mysql if you do what you are doing it will bring 1969-01-01

  • I get it, there’s no way to fix this ?

  • 1

    Patching is never the best option, the right one and fix. You can set the field to NULL. NULL is different from empty, you will have to treat this in PHP and tell SQL that you want to leave the field worthless.

  • I’ve adjusted, and also in mine get I made a condition if when the date is 01-01-1970 it shows nothing if it does not show the date.

  • 1

    You can set the field to a default value, that is, when you do not save anything to it, the field will take the default value, is the best option for you, instead of comparing strings.

  • Right, but I don’t even want a value I want to be left with nothing. Want by this answer set a default value put for me to see if it is viable.

  • Hello Kevin! Could you edit the question with the table creation script? Make sure the column is set to accept null..

Show 2 more comments

1 answer

1


When you send an empty field SQL Server does not understand what you want, so it puts a date by default.

You have two exits in my view right now.

1) Perform a test in your application, when the field is empty, ask the user to fill in this field

2) If you still want the blank field, it is enough SET NULL at the time of Insert.

See if this helps you understand better:

SQL Server inserting Date as 1/1/1900

Browser other questions tagged

You are not signed in. Login or sign up in order to post.