Created
July 23, 2017 19:14
-
-
Save skojin/69031d89974fd7ba472164179a22062f to your computer and use it in GitHub Desktop.
util to map datetime column to date in current timezone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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