panthro
panthro

Reputation: 24061

Store null time in datetime field?

I need to store a start and end datetime.

Sometimes it is just a date, and others it also includes a time.

Can you store a date with a null time (using 00:00:00 for an empty time would not work incase this was the actual start time).

Or would it be advised to have a separate date and time field, storing null in time if no time was passed?

Upvotes: 0

Views: 112

Answers (1)

slaakso
slaakso

Reputation: 9050

A datetime is a datatype which contains both the date and the time part, and the other one cannot be null.

If you need to have separate case where the time can be null, you have two options: use separate fields to the date and the datetime or use separate fields for date and time. The best solution really depends on what the data represents (if it is a same thing or a different thing in real life).

Upvotes: 1

Related Questions