Date Parsing problem while Integrating to Oracle PMS

I'm recieving date in PMS message something like this |GA090616|GD090617| which means Guest Arrival is at 09-06-16 and Guest Deprature is at 09-06-17

I wanted to parse it as date using python.

I've also visited stack oveflow[1, 2 ...] for this but as solution I've found

from datetime import datetime

self.DATE_FROMAT='%d/%m/%y'

arrival_date=datetime.strptime('90616', self.DATE_FROMAT).date()
print(arrival_date)

and it's not possible to parse it like this due to it's not in clear format. not able find out 09 is month or date as far I got from docs and pdfs it seems month.

is there any better solution for this kind of date parsing? or suggestion for my expectation.

{
   guest_arrival: 09-06-16,
   guest_deprature: 09-06-17
}

You can do this with regex matching, you can either split the string with msg.split("|") or not, but that depends on your use case.

import re
from datetime import datetime

msg = "GA090616|GD090617|"
DATE_FORMAT='%d%m%y'

ar = re.match("GA(\d{6})", msg)
dp = re.match("GD(\d{6})", msg)

guest_arrival = datetime.strptime(ar.group(1), DATE_FORMAT).date()
guest_departure = datetime.strptime(dp.group(1), DATE_FORMAT).date()

Although not fully tested, this should be a boilerplate as to how to retrieve the date from the message. Remember to remove the \ from the date format, as that is not included in the message.

Back to Top