I have a few datetime columns to bulk update. Originally because this data is being used as a demo I had used this to update my date columns to more recent dates.
UPDATE tblVehicleReservation
SET [PredictedJobEndDate] = GETDate()
WHERE [PredictedJobEndDate] IS NOT NULL
It has now come to light that these are needed with the time as 00:00:00.000 as opposed to 13:00:32.957 while keeping the date part the same.
After researching the only resolutions I found to this converted my date to a string.
Ideal Resolutions
Something I can use to set the time on each date to 0's.
A hint how to go through the update process again entirely and set a date without 0's
I figured this out while writing it...
I decided to just run the updates again and set the date manually instead of using GetDate().
Duh.
Related
I've linked Google data studio with a MySQL database using the standard connector. Everything works except sorting correctly by date.
Database columns configured like this:
price decimal(15,2) not null 24.59
last_changed timestamp not null 2019-03-25 19:24:52
GDS datasource fields configured (as per this answer) like this:
last_changed Date(YYYYMMDD) 2019-03-25
sold_at GDS function TODATE(last_changed, 'DEFAULT_DASH', '%Y%m%d')
GDS bar chart configured like this:
time dimension sold_at as date
dimension sold_at as date
value metric price as sum
sorting sold_at as date ascending
time range auto from date picker with default set to current month
I am experiencing the following issue: When sorting is set to sold_at the bar chart is empty with the default date range. Only when i go back at least one month it displays values in the chart but also cuts off the last day so that its less than it should be. Only when sorting is set to price it displays everything correctly, even in the current month. Also when switching from sorting set to price to sold_at while the default time range is selected it shows the sold_at field under Invalid in the sorting modal.
I tried modifying the database column to datetime instead of timestamp but it didnt change anything. I also tried setting a different default time range but that doesnt change anything also. It keeps showing no data for 1 month back.
Any idea or someone who already stumbled across this scenario?
For people that come across the same issue:
This issue was caused by the MYSQL timestamp/datetime column having optional Hrs:Min:Sec. This caused the GDS mysql query to not be able to group them by day and thus resulting in more than 100000 rows, which is more than the hardcoded limit set by the connector.
Solution: Added another timestamp/datetime column and filled it with
UPDATE table SET newcolumn = DATE_FORMAT(oldcolumn, '%Y/%m/%d');
It now works like a charm.
According to what I've read in some posts such as the answer for this question
passing null value in a timestamp field will store the date when the row was created, but will update it when row is edited.
I want to do the same thing but without changing the date, and having that time stored as UTC, how can I do that?
The best approach is to create a trigger to apply the change, or do it in your application code.
As a note, TIMESTAMP fields are really awful and shouldn't be used as they are subject to the 2038 overflow issue while DATETIME is not. A DATETIME can go thousands of years into the past and into the future, which is hopefully enough.
I'm trying to apply 'curdate()' functionality to a select statement from DB2. I'm used to MySQL but I'm still trying to get the hang of a lot of the DB2 functionality and how to essentially marry the two.
My query is complete except for one line. I'm trying to select based on a ship date, which is the column EXTD1H and I need to check it against today or curdate(). The problem is that column in DB2 is an integer format, not a date format, and I don't have the option of changing it. In prior inserts to mysql, I've been able to put it into Y-m-d format and I know I can trim the year using LEFT(EXTD1H, 4) but I have no idea how to modify my select so that I can say WHERE EXTD1H is today so that I'm only selecting records for this date.
Here's the query:
select
invnoz as ORDER,
fstatz as STATUS
from gportafl
/*where EXTD1H is curdate, hypothetically*/
AND FSTATZ <> 'S'
limit 20;
As you can see, I have a commented line where my issue is. I'm sure it's simple I just can't seem to find in the documentation exactly what I'm looking for, which is to be able to use that INT column to verify that selected records are from today.
UPDATE:
All values from the column are in YYYYMMDD format i.e.
20180202
but it should be 2018-02-02
It's best not to do operations on the columns, so the indexes are used.
You can typecast the current date to fit your data as follows:
WHERE extd1h = INTEGER(VARCHAR_FORMAT(CURRENT DATE,'YYYYMMDD'))
I have a Mysql 5.5 and a table with a column as follow:
`VERSION_TS` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
but i'm having difficulties lately i'm getting this exception:
Incorrect datetime value: '1998-03-20' for column 'VERSION_TS' at row
1
when trying to enter values to the table, values of type Date, using mySql MakeDate().
Now, i can't change the function that return Date, but i can change the column to Date, but then i'll lose the default value. i've tried a couple of things, and then checked the web, and from what i understand in Mysql 5.5 there is no way to do it, but i could be wrong, so i came here to ask:
Is there a way that i can change the column to a Date and still have
a default value?
Also, is there a better way to do approach the problem?
I think the documentation is quite clear on this point:
TIMESTAMP and DATETIME columns can be automatically initialized and
updated to the current date and time (that is, the current timestamp).
So, this does not apply to DATE. However, you could create a view that does what you want:
create view v_table as
select t.*, date(version_ts) as version_date
from table t;
if the function which returns date is written in php then after receiving the date value you can do this:
$date = new DateTime('2006-12-12');
echo date_format($date,'Y-m-d H:i:s');// this you can store in mysql table.
if not same kind of approach you can apply in the respective language to do the job.
OR work with view as Gordon Linoff mentioned.
I have a simple problem for which I found a solution in early testing but cannot replicate now that I need to do it for real.
We are moving our news system from CuteNews to our self-built MySQL system. All the news has been imported into the database but the date field is Timestamp. I have created a new field (created_date) and want to populate this from the Timestamp in the date field.
As I said, I did do this previously in an early trial run and was convinced that the query I used, via PhpMyAdmin was along the lines of UPDATE News set created_date=UNIX_TIMESTAMP(date). This is probably slightly wrong as I am at work and posting from my phone but it was along those lines.
No errors were returned but all 'created_date' fields were populated as 0000-00-00 00:00 not with the date taken from the Timestamp in the date field.
I know it is simple and know the answer will be obvious when I see it but any pointers would be gratefully appreciated!
Steve.
EDIT: reading back through I realised a bit of what I posted may be misleading. In my original trial run using the update query put the correct DateTime in the field based on the corresponding Timestamp field. It is only this time that it shows 0000-00-00 00:00.
Ps. Thanks for the format tidy-up. It's a bit awkward on a phone!
I knew I was nearly there!! It was not UNIX_TIMESTAMP but FROM_UNIXTIME I was after.
UPDATE news SET created_date = FROM_UNIXTIME(date)
Thanks for the help.
Steve