Skip to main content
Solved

MySQL date/time field

  • February 28, 2017
  • 5 replies
  • 35 views

redgeographics
Celebrity
Forum|alt.badge.img+48

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?

Best answer by david_r

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

View original
Did this help you find an answer to your question?

5 replies

david_r
Evangelist
  • Best Answer
  • February 28, 2017

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


redgeographics
Celebrity
Forum|alt.badge.img+48
  • Author
  • Celebrity
  • February 28, 2017
david_r wrote:

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

 

 


david_r
Evangelist
  • February 28, 2017
redgeographics wrote:
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 :-)

 


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • February 28, 2017
redgeographics wrote:
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.

 


Forum|alt.badge.img
  • February 28, 2017

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()


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings