SQL Server Storing DateTime as Integer -


i adding tables data warehouse , want store datetime information int field (the time part not important me)

note i'm not storing 20150123, store pure integer using

cast(field int) 

that stores 2015-06-18 12:57:47.833 42172

i can add day +1 , add week adding 7 field. adding month not straight forward. whenever need date representation of data, can cast datetime.

just want know pros , cons see on this?

converting between int , datetime works fine. it's defined conversion does, there nothing mysterious going on might change or stop working.

let's @ aspects:

  • comparable: yes; can still compare numbers tell date earlier.
  • sortable: yes; can sort on int , it's sorted date.
  • readable: no; have convert datetime make sense of it.
  • self-explanatory: no; have know number represents it.
  • portable: yes; can same conversion in system supports date arithmetics.

you can example same conversion int datetime in c#:

datetime d = new datetime(1900, 1, 1).adddays(42172); 

when comes storage space, there isn't advantage. int uses 4 bytes , datetime uses 8 bytes. if need preserve space, should rather use date type, uses 3 bytes.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -