I have a geodataframe which I'm adding some column data to, all the same length, to get this in the correct format for another application I do the following:
revdate = datetime.date(1999, 12, 20).strftime("%Y-%m-%d")
gdf = gpd.GeoDataFrame()
gdf['revdate'] = revdate
gdf['revdate'] = pd.to_datetime(gdf['revdate']).dt.strftime("%m/%d/%Y")
Incorporating PyQt5 I use a DateEdit
field, I need to go through the same procedure as above:
revdate = self.dateEditRevDate.date()
gdf = gpd.GeoDataFrame()
gdf['revdate'] = revdate
gdf['revdate'] = pd.to_datetime(gdf['revdate']).dt.strftime("%m/%d/%Y")
The date is received This date is in format PyQt5.QtCore.QDate(2000, 1, 1)
It trips up on this line:
gdf['hs2_revdate'] = pd.to_datetime(gdf['hs2_revdate']).dt.strftime("%m/%d/%Y")
With a type error TypeError: <class 'PyQt5.QtCore.QDate'> is not convertible to datetime
Any pointers appreciated.
Don't get too complicated trying to use QDate as you can convert it to datetime.date()
using the toPyDate()
method:
revdate = self.dateEditRevDate.date().toPyDate().strftime("%Y-%m-%d")