[FIXED] How to change the dateTime format to Date


In the response i am getting date as 2022-08-12 00:00:00

appointmentDateTime = jsonResponse.jsonPath().getString("appointment.date");

But when i need to pas the same value in DB query i need to send only the Date 2022-08-12 need to remove the Time


So your input is 2022-08-12 00:00:00 and you want to only extract the date without time. This you can achieve using the split() method.

I am assuming appointmentDateTime is in String data type.

String[] onlyDate = appointmentDateTime.trim().split(" ");

onlyDate[0] would represent the first element which would be 2022-08-12, and onlyDate[1] would represent the second element which will be 00:00:00

Answered By – cruisepandey

Answer Checked By – Mildred Charles (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published