0

I am using Joda DateTime function in scala to validate the year format as follows

def isValidDateType(value: String, Date_format: String): Unit = {
    val fmt = DateTimeFormat forPattern Date_format
    val output = fmt parseDateTime value
    println(output)
}

isValidDateType("20156-06-06","yyyy-MM-dd")

Output : 20156-06-06T00:00:00.000+05:30

isValidDateType("201-06-06","yyyy-MM-dd")

Output: 0201-06-06T00:00:00.000+05:53:28

Is there any way to validate this year format ?

Simon
  • 6,025
  • 7
  • 46
  • 98
  • What does this have to do with spark ? – eliasah Jul 01 '16 at 06:33
  • 1
    Possible duplicate of [Java date validation joda time](http://stackoverflow.com/questions/33082641/java-date-validation-joda-time) – eliasah Jul 01 '16 at 07:24
  • I am validating spark datetype using scala code – unusskhan Jul 01 '16 at 07:27
  • it's still has nothing to do with spark. I don't any spark reference in your code. This is just scala and joda – eliasah Jul 01 '16 at 07:28
  • 1
    The year 20,156 and 201 are in principle both valid values for years. Just because you have `yyyy` in your pattern doesn't mean that the year has to be exactly 4 digits. If you require this, write code that checks if there are exactly 4 digits before the first `-`. – Jesper Jul 01 '16 at 07:32

0 Answers0