Skip to main content

Hi,

I'm writing data to a MySQL (non-spatial) database and have some problems getting datetime fields filled. Checking a sample table in phpMyAdmin shows the date format to be ^Y-^m-^d ^H:^M:^S, e.g. 2017-02-28 13:09:00, so I've set up my TimeStamper to output that. But when I write to the database it fails every feature with a message saying it's an invalid format.

If I enter the same value directly through phpMyAdmin it's accepted.

Any idea what I'm doing wrong?

Try formatting your timestamps as "FME Date/Time (^Y^m^d^H^M^S)" before the writer.


Try formatting your timestamps as "FME Date/Time (^Y^m^d^H^M^S)" before the writer.

Yes, that's it, thanks! Funny thing is that phpMyAdmin still reports it as ^Y-^m-^d ^H:^M:^S

 

 


Yes, that's it, thanks! Funny thing is that phpMyAdmin still reports it as ^Y-^m-^d ^H:^M:^S

 

 

Timestamps are usually stored as some type of floating point number in most databases, but since that doesn't make much sense for the end user most client applications format the number before printing it on screen, usually according to the date format that's active on the machine that renders the display (its locale settings). So what phpMyAdmin is showing isn't necessarily exactly what's in the database, but its own, user-friendly representation of the contents.

 

 

Current versions of FME (up to and including 2016) has a "fake" interpretation of timestamps, where they're represented as strings internally, not floats. It is the writer that ultimately converts that string into whatever format the target requries, and when doing that it assumes that the incoming string be supplied as "FME Date/Time" or some variant thereof.

 

 

Someone from Safe please correct me if my assumptions are wrong :-)

 


Yes, that's it, thanks! Funny thing is that phpMyAdmin still reports it as ^Y-^m-^d ^H:^M:^S

 

 

In my observation, it seems that many FME writers supporting datetime type accept datetime values with the FME data/time format (i.e. %Y%m%d%H%M%S) and convert them into the format acceptable by the destination format automatically before writing. In most cases, therefore, the user doesn't need to know the date/time format specific to the destination format, as long as they uses an appropriate writer. Probably the MySQL writer also has the mechanism to convert datetime format automatically, I think.

 


You can always use python.  Then format in the python code to exactly how you want.  Their is a ton on this.  

https://docs.python.org/2/library/datetime.html

import time
from datetime import date
today = date.today()


Reply