0

I kind of stuck on this one. Basically, we have a string that is actually a date with a format YYYYMM. For example, 201901.

I wanted to convert this into a date record, but I found out that we could not set a particular date format in the method 'format()'.

Is there any way I could create a date record with date format YYYYMM?

Thanks.

1 Answer 1

2

You can use the method newInstance to achieve this.

Date myDate = date.newinstance(1960, 2, 17); //YYYY, MM, DD

Just split the string (You can use substring(startIndex, endIndex) ) and pass in the method. For the day you may need to pass a static value(like 1).

3
  • 1
    Oh yeah. Now I understand. Thanks for the suggestion of having the date as just a static value. I actually forgot about that one, that's why I didn't use newinstance. Yes, I think this would work for me. Jan 29, 2019 at 13:26
  • @JerardDelaVictoria If this solves your problem then you can accept the answer and close this question. Jan 30, 2019 at 7:31
  • sorry for the late reply. yup. I coded this and it works! Thanks for the help. Feb 1, 2019 at 6:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .