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.6K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 102 SQL DataFlows
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 755 Beast Mode
- 61 App Studio
- 41 Variables
- 693 Automate
- 178 Apps
- 456 APIs & Domo Developer
- 49 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 398 Distribute
- 115 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 11 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 110 Community Announcements
- 4.8K Archive