Skip to content

Instantly share code, notes, and snippets.

@skojin
Created July 23, 2017 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skojin/69031d89974fd7ba472164179a22062f to your computer and use it in GitHub Desktop.
Save skojin/69031d89974fd7ba472164179a22062f to your computer and use it in GitHub Desktop.
util to map datetime column to date in current timezone
# SQL timezone time/date related utils
module SqlTz
extend self
# convert time to date with respect to timezone
# example: where("#{SqlTz.time_to_date(:created_at)} = ?", Date.today)
def date(column)
"DATE(DATE_ADD(#{column}, INTERVAL #{Time.current.utc_offset} SECOND))"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment