Date Field Added 1 Day To Itself.
I have a date field that includes the time stamp. I used the CAST to simplify the date and rmeove the time stamp. When I do that, the date increases by 1 day. Any help? See attached
Best Answer
-
This may be occuring if you have your Company Time Zone Settings set to your local time.
If this is the case, then when you begin using native SQL commands, it treats the time within those commands at UTC time. If you are West of the Central Time Zone then you are at least -7 hours from UTC, so in your example the system is probably reading your original date as November 27, 12:23 AM and casting that timestamp as DATE.
Your solution will probably be to ensure that you are converting your timestamp from UTC to Local Time (or vice versa if I have this backwards) and then casting that as a date:
CAST(CONVERT_TZ(`date_created`,'UTC','MET') AS DATE) AS `Date_Created`
Note: You will need to look up the abbreviation for your time zone.
Extra Note: Try running the code without the CAST to see how the times are being converted. You may want to run the data flow completely to see what happens to the data when it displays in the output data set
1
Answers
-
This may be occuring if you have your Company Time Zone Settings set to your local time.
If this is the case, then when you begin using native SQL commands, it treats the time within those commands at UTC time. If you are West of the Central Time Zone then you are at least -7 hours from UTC, so in your example the system is probably reading your original date as November 27, 12:23 AM and casting that timestamp as DATE.
Your solution will probably be to ensure that you are converting your timestamp from UTC to Local Time (or vice versa if I have this backwards) and then casting that as a date:
CAST(CONVERT_TZ(`date_created`,'UTC','MET') AS DATE) AS `Date_Created`
Note: You will need to look up the abbreviation for your time zone.
Extra Note: Try running the code without the CAST to see how the times are being converted. You may want to run the data flow completely to see what happens to the data when it displays in the output data set
1 -
Thanks for the info. I tried all kinds of variations and even MySQL but just can't get it to work. Anything with a time stamp after 5:00PM in my records gets converted to the next day. I'll try a beastmode and see if I can trim it down there. Idealy I always like to do as much as I can in the underlying query.
Thanks again!
0 -
I think your bet bet to figure it out is to continue to experiment with additonal columns to figure out where the system is changing your dates. Check to see what happens when you write:
CAST(a.date_created as datetime) as 'Date Set'
and then run the data flow. This should give you a hint as to what happens when you use the CAST function in a MySQL data flow. If it returns the exact same time as your a.DATE_CREATED then surely you can just just wrap it into this:
,DATE(CAST(a.date_created as datetime)) as 'Date Set'
If the CAST as datetime statemtent returns something like November 27, 12:23:56 AM then you know there is some converting that needs to be done. It may even require a two-step data transform where you convert in the first transform, and then CAST as DATE or write DATE('date set') in a second transform.
I am so bummed because I must have deleted my timezone notes for this behavior after I switched our company time zone settings to UTC. It also means I can't exactly replicate the problem but hopefully this can be a nudge in the right direction.
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.8K Visualize
- 2.5K Charting
- 738 Beast Mode
- 56 App Studio
- 40 Variables
- 684 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 46 Workflows
- 10 DomoAI
- 35 Predict
- 14 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 123 Manage
- 120 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive