Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timezone conversion in SELECT query #11

Open
magiruuvelvet opened this issue Nov 4, 2023 · 0 comments
Open

timezone conversion in SELECT query #11

magiruuvelvet opened this issue Nov 4, 2023 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@magiruuvelvet
Copy link
Owner

This might be useful in the future.

Retrieve the timezone offset from UTC.

#include <iostream>
#include <chrono>
#include <ctime>

int main()
{
    std::time_t now = std::time(nullptr);
    std::tm local_time = *std::localtime(&now);
    int offset_minutes = local_time.tm_gmtoff / 60;
    std::cout << "Timezone offset from UTC: " << offset_minutes << " minutes." << std::endl;
    return 0;
}

Perform timezone conversion directly from a SELECT statement.

fmt::format("select datetime(timestamp, 'unixepoch', '{}{} minutes')", offset < 0 ? '-' : '+', offset);
@magiruuvelvet magiruuvelvet added the documentation Improvements or additions to documentation label Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant