How to validate two date with in 24 hours

i am new at robot framework
want to validate two 28/12/2022 and 29/12/2022 with in 24 hour

29/11/2022 12:00 PM IST’ actual time fetch from ui ${form1}

     ${from}  Get Text  ${locator}
     ${To}  Get Text  ${locator}
     ${from1} =	Convert Date  ${from}  exclude_millis=yes	date_format=%d/%m/%Y %I:%M: %p
     ${To1} =	Convert Date  ${To}  exclude_millis=yes	 date_format=%d/%m/%Y %I:%M: %p
     ${Subtract_Time1}  Subtract Date From Date  ${To1}  ${from1}
     Log To Console  ${Subtract_Time1}

after that I get
time data ‘29/11/2022 12:00 PM IST’ does not match format ‘%d/%m/%Y %I:%M: %p’

Hi Pratik,

Save this as rahul12.robot and run it, it should help you understand where your issues were.

Dave.

rahul12.robot

*** Settings ***
Library		DateTime

*** Variables ***

${badfrom}		29/11/2022 12:00 PM IST
${from}		28/11/2022 12:00 PM
${To}		29/11/2022 12:00 PM
${ToLong}		29/11/2022 12:02 PM

*** Test Cases ***
rahul12 Bad Parse 1
	Log    This will faile because of the : after the %M
	${from1} =	Convert Date  ${from}  exclude_millis=yes	date_format=%d/%m/%Y %I:%M: %p

rahul12 Bad Parse 2
	Log    This will faile because of the IST
	${from1} =	Convert Date  ${badfrom}  exclude_millis=yes	date_format=%d/%m/%Y %I:%M %p

rahul12 Date Time Test
	${from1} =	Convert Date  ${from}  exclude_millis=yes	date_format=%d/%m/%Y %I:%M %p
	${To1} =	Convert Date  ${To}  exclude_millis=yes	 date_format=%d/%m/%Y %I:%M %p
	${Subtract_Time1}  Subtract Date From Date  ${To1}  ${from1}
	Log To Console  ${Subtract_Time1}
	Should Be True    ${Subtract_Time1} <= 86400

rahul12 Date Time Test Long
	Log    This will faile because it's more than 24 hours (86400 sec)
	${from1} =	Convert Date  ${from}  exclude_millis=yes	date_format=%d/%m/%Y %I:%M %p
	${To1} =	Convert Date  ${ToLong}  exclude_millis=yes	 date_format=%d/%m/%Y %I:%M %p
	${Subtract_Time1}  Subtract Date From Date  ${To1}  ${from1}
	Log To Console  ${Subtract_Time1}
	Should Be True    ${Subtract_Time1} <= 86400

Also you cane use String Library’s Replace String to remove the IST if you need to

${from}=	Replace String		${badfrom}		IST		${EMPTY}

Thanks damies13

     ${Var_from}  Get Text  ${locator}
     ${Var_To}  Get Text  ${locator}
     ${from} =  Replace String  ${Var_from}  IST  ${EMPTY}
     ${from1} =	 Convert Date  ${from}  exclude_millis=yes	date_format=%d/%m/%Y %I:%M %p
     ${To} =  Replace String  ${Var_To}  IST  ${EMPTY}
  ${To1} =  Convert Date  ${To}  exclude_millis=yes  date_format=%d/%m/%Y %I:%M %p
  ${Subtract_Time1}  Subtract Date From Date  ${To1}  ${from1}
   Log To Console  ${Subtract_Time1}
   Should Be True    ${Subtract_Time1} <= 86400

after that I get Value Error: unconverted data remains
how deal with these

Hi Pratik,

You might need to do this:

${from}=	Replace String		${badfrom}		${SPACE}IST		${EMPTY}

as the space after PM and before IST might also be causing you an issue

Dave.