Skip to content

Instantly share code, notes, and snippets.

@technetium
Created October 14, 2023 19:17
Show Gist options
  • Save technetium/f8080a27917955ad686906dc6ddee7d4 to your computer and use it in GitHub Desktop.
Save technetium/f8080a27917955ad686906dc6ddee7d4 to your computer and use it in GitHub Desktop.
MySql function to convert decimal degrees to Half, Decimal and Minutes
CREATE FUNCTION D_TO_HDM(value FLOAT, halfs TEXT)
RETURNS TEXT
RETURN CONCAT(
IF(value > 0, LEFT(halfs, 1), RIGHT(halfs, 1)), FLOOR(ABS(value+1/120000)) , ' '
, LPAD(FLOOR((ABS(value+1/120000)-FLOOR(ABS(value+1/120000)))*60), 2, "0") , '.'
, LPAD(ROUND((ABS(value+1/120000)*60-FLOOR(ABS(value+1/120000)*60))*1000), 3, "0")
)
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment