Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Convert FM Date field to MySQL timestamp(8)

Featured Replies

Hi,

I am exporting data to a MySQL database from ODBC but date formats are causing a headache..

FM Date = 3/2/2006

MySQL Timestamp(8) = 20060302

Is there an easy to convert from FM to MySQL date format. At the moment the export script goes something like ....


 Set Variable [$startDateDay; Value:Day(Events:event_startDate)]

 Set Variable [$startDateMonth; Value:Month(Events:event_startDate)]

 Set Variable [$startDateYear; Value:Year(Events:event_startDate)]



 If[$startDateDay < 10]

     Set Variable[$startDateDay; Value: "0" & $startDateDay

 End If



 If[$startDateMonth < 10]

     Set Variable[$startDateMonth; Value: "0" & $startDateMonth

 End If



 Set Variable [ $startDateMySQL; Value:$startDateYear & $startDateMonth & $startDateDay ]

But when I have 15 different dates in the table it becomes very annoying to write all the scripts...

Any suggestions?

Thanks

Matt

You don't need a ( 15 ?) script, but you need to export a calculated text field (15 calc fields) with calc:

Year(date) & right("0" & month(date);2) & right("0" & day(date);2)

  • Author

Thanks for the response, think I need a book on FM scripts....

I have however come up with a custom function which I can just call while doing the Execute SQL script step...


/* fmDate_to_MySQL_Timestamp8(fmDate) */

/* Convert a Filemaker DATE field to a MySQL Timestamp(8) field */



Let([

	fmDay = If(Length(Day(fmDate)) < 2; "0" & Day(fmDate); Day(fmDate) );

	fmMonth = If(Length(Month(fmDate)) < 2; "0" & Month(fmDate); Month(fmDate));

	fmYear = Year(fmDate)

];

Case( 1 = 1; fmYear & fmMonth & fmDay; fmYear & fmMonth & fmDay))

Will look at the Right function, I was trying to find that earlier but kept searching for Pad or something....

This custom does the same calculation...with a little more complexity !

Hi Matt,

You need to update your profile to reflect that you have [color:blue] Advance , as this can make a difference it the responses we can give.

Lee

Edited by Guest

  • Author

Thanks.

Profile updated.

raybaudi, couldn't see your function anywhere...

Sorry...

I had to say :"that" custom (the custom function that you showed us)

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.