Explore Courses Blog Tutorials Interview Questions
+1 vote
in Big Data Hadoop & Spark by (830 points)

I am importing some data from an MS SQL table to Scala program. MS SQL table has around 20 fields so I am making a class to load those rows in my Scala program.

  1. In MS SQL there is one column whose data type is datetime, how do I store this kind of data type in my Scala program, I don't think Scala has this data type?

  2. There is one more column Price (numeric(14,4),not null) whose data type is numeric in MS SQL. How do I store these kind of values in Scala ?

2 Answers

0 votes
by (13.2k points)
edited by


For Scala, we can import datetime package from java libraries.

For JAVA 8 + ,

Import the date object and formatter that is




then, parse the string to date


then format the date to string,

date.format(DateTimeFormatter.ofPattern("[preferred format]"))

NOTE : By default, the ISO format is followed which is YYYY-MM-DD

For JAVA 7,

Use SimpleDateFormat to define format, 

 val originFormat = new SimpleDateFormat("[initial format]")

 val targetFormat = new SimpleDateFormat("[required format]")



For price column, you can use float or double data type


32 bit IEEE 754 single-precision float


64 bit IEEE 754 double-precision float

Enroll in the Scala course in Singapore to get professionally certified.

0 votes
by (32.3k points)

You can practice DateTime, Scala uses a lot of Java libraries and so on beneath. So you can surely use DateTime. I'd like to recommend looking at the DateFormatter. If you want more information regarding the same, refer to the following video:

Browse Categories