I wonder how to go about creating an expression in Java that takes a date variable formatted as “1999-12-30 12:34:45” and converts it to an Int holding “19991230”.
This is probably something others would appreciate, especially people extracting and cleaning up data for loading into a Data Warehouse.
My guess is one need to change date pattern, convert to string, truncate first part (8 chars) and convert to int.
Ideas?
(update)
My bad in explaining the issue.
The resulting int will service as a key/Fk id to a Date Dimension. A similar operation should be done for creating a key to a Time-of-Day Dimension. The int will reduce the size consumed in the facts table, in which these int keys would be stored. See related answer: https://stackoverflow.com/a/8416548/1132571
Pretty easy to do this using the SimpleDateFormat class. However, as others mentioned you probably should be storing the epoch timestamp as Database TimeStamp column instead of storing the date in an int form. It will cause problem later when you are manipulating the data with SQL.