am trying to export alle the change history of all my trac tickets via a tab delimited text file export.
I successed so far with the following SQL Statement:
SELECT
id AS Ticket,
tc.author as author,
tc.field as field,
tc.newvalue as comments_new
from ticket t
LEFT JOIN ticket_change tc ON ( t.id=tc.ticket )
But I need also the time and date of each entry. There is a field time in the table ticket_change but it is only the time without the date.
Seems like I have to use some functions within the SQL to get what I need. Can anybody help me to get there?
Every Help is very appreciated.
Best Regards
Ali
The time field is an integer representing epoch microseconds. You can use the Trac utility trac.util.datefmt.from_utimestamp to convert the value to datetime format. That only helps if you are working in Python though. In other languages, you can use recipes for converting from unix seconds. Note you must divide the value in Trac by 1e6 first, to convert from microseconds to seconds.
Related
I have a large dataset with employees' time entries. The current date format is MM/dd/yyyy. However, I need to convert all the dates into yyyy-MM-dd format.
I have tried the following:
Update human_resources.timekeeping
Set Actual_Date = str_to_date(Actual_Date,'%d-%m-%Y');
Got the errror messsage Error Code: 1411. Incorrect datetime value: '' for function str_to_date.
My SQL version is 5.7.18-log.
I tried to view SQL mode using SELECT ##sql_mode; and I got NO ENGINE SUBSTITUTION.
I have tried to retrieve the value like shown below and it was working fine.
Converting varchar mm/dd/yy to date format yyyy-mm-dd
However, updating the data would not work. I need to update the actual records, not insert new records.
Hope someone can help me regarding this. Thank you in advance!
EDIT: The data type for Actual_Date is VARCHAR.
Apologies if my explanation may be a bit confusing. But I am using this data set to display and filter time entries in a gridview. When I am filtering dates, say for example (01/15/2022-01/25/2022), data from 2021 is also being displayed. When I tried to manually change the format of some of my data in sql to yyyy-MM-dd, my code seemed to be working fine. The problem is there are a lot of data in this table, which is why manually updating the format is impossible. What is the first thing that I need to do? I'm sorry this is all still a bit confusing for me.
My apologies if you have already taken the following things into consideration but I thought them worth mentioning.
Given that you say this is a "large dataset" I assume this is a table that is currently in use. Does the existing application rely on the Actual_Date being in that string format? Does it rely on a fixed number of columns in the table? Some poorly written applications can be very brittle when it comes to changing underlying data structure.
You may want to consider creating a copy of the current table, modifying the structure of the copy, and replacing the original with a view with the same columns and formats as the original. This way you get improved data but reduce risk to existing application.
In the title and first line of your question you state that the current format is MM/dd/yyyy
Update human_resources.timekeeping Set Actual_Date = str_to_date(Actual_Date,'%m/%d/%Y');
Your separator is / not -
%d-%m-%Y >> %d/%m/%Y
I need to import a large file of csv data into MySQL, and when I attempted to use MySQL's unix_timestamp function to import the dates, about half of the records didn't make it.
As far as I can tell, the datetime values are formatted with either a single first "month" digit or two of them, and the same goes with the day of the month (e.g. 6/6/2014 3:48PM vs. 12/16/2014 3:48PM) This throws off the import completely (well about half of the records won't import).
I'm trying to convert this into a unix_timestamp.
Now I know I could write a script with a regex to fix something like this, but I am wondering is there a simpler way to do a mass import like this? For the record, I am using my text editor to write the sql statements from the csv as "insert into" statements. This is where I tried to use date formatting but it seems to only accept one format.
Any way to do this with such a minor difference in input?
Actually, despite my comment, something like this might work:
COALESCE(STR_TO_DATE(val, "formatcandidate1")
, STR_TO_DATE(val, "formatcandidate2")
, STR_TO_DATE(val, "formatcandidate3")
, STR_TO_DATE(val, "formatcandidate4")
, [etc...]
) AS dateVal
There are online tools to do this kind of stuff
reports.zoho.com is one of them
In this tool you can import data applying a specific date format and skip the other rows.
and you can do the same for all the type of formats that are present in your file
and finally you can export the data with same date format for all the data
ask me any doubts if you have any regarding this :)
I am trying to import a CSV file with date information in the format MMM-YY (e.g., Jan-92). My ultimate goal is to have the information in a date format in SQL. The format doesn't matter that much to me, but I was thinking something like dd-mm-yy (e.g., 16-01-92). I've tried a lot and looked around the forum, but can't figure it out.
Right now, I am loading the data from the CSV into a column "period_month" as a VARCHAR field.
Then, my conversion code looks like
UPDATE PERIODS
SET period_month = DATE(str_to_date(period_month,'%M-%Y'));
I end up with a field of VARCHAR type in the format yyyy-mm-dd, with the dd field set to '00'. (e.g., 1992-01-00)
I really just want this to be in a date format that I can export to another program like R for analysis.
Any help appreciated.
try
UPDATE PERIODS
SET period_month =DATE(str_to_date('Jan-92','%M-%Y')+1)
or
UPDATE PERIODS
SET period_month =DATE(str_to_date('period_month','%M-%Y')+1)
use date_format function of mysql query
I have the output of a SQL Server 2008 query saved to a text file and I am trying to link it to an Access database (Access 2007-2010).
The text file contains two date columns in the SQL Server 2008 datetime format, like this:
EFFECTIVE START DATE:
---------------------
2013-07-01 00:00:00.000
EFFECTIVE END DATE:
-------------------
2014-06-30 00:00:00.000
In the Import wizard, I click Advanced and change the following:
Code Page = Western European (Window) instead of Unicode (UTF-8)
For the 2 datetime columns:
data type = Date/Time
date order = YMT
Date delimiter = -
Leading zeros in dates = ticked
While still in the import wizard the data looks fine but as soon as the import is finished and I open the table in Access, I see #Num! in the two date columns.
I have tried a combination of settings in the import wizard (leave the code page as Unicode, not change the date order, not ticking the leading zeros in dates, etc) but in the end I had to import the dates as text, which stops me from doing any calculations now.
Many thanks in advance for the help
in the end I had to import the dates as text, which stops me from doing any calculations now.
True, you can't manipulate the text fields as true dates, but you can run a make-table query to convert them to real Date/Time values like so:
SELECT
ID,
CDate(Left([Field1],InStr([Field1],".")-1)) AS Date1,
CDate(Left([Field2],InStr([Field1],".")-1)) AS Date2
INTO SqlDataWithRealDates
FROM SqlData;
The issue with the original import is that Access Date/Time values do not support fractional seconds so Access will never recognize the values as such if they include 00:00:00.000. The above query removes the trailing .000 before passing the strings to CDate().
Another alternative as suggested by Johnny Bones in the comments below is to alter the SQL Server query to use something like CONVERT(VARCHAR(10), [Field1], 101) AS Date1 to remove the time component from the strings that will eventually be imported.
I'm just adding this as an answer, since it ended up being the one that worked:
If you have control over the output from SQL Server, you can change the format of the date field in your view/stored procedure. Something like
SELECT CONVERT(VARCHAR(10), [Field1], 101) AS Date1
That will strip the time off it, and Access should recognize it.
I found if you use "M/d/yyyy HH:mm:ss" as the date format (.NET), Access will import the date/time correctly, at least for if you are in the United States. Note, the hour is the 24 hour time. It won't work in 12 hour time with the AM/PM indicator. This is different than Excel, which does work with the 12 hour time. If you include milliseconds, it won't work. You can leave the time off if you don't need it.
If your output is CSV file, change the output format to "MM/DD/YYYY", and drop the time from the date.
It will import just fine.
If you need to use the time, make another column for it, and strip out the date leaving only the time.
I was able to use hundreds of hours with two places.
Access does import correctly the date and time information in the data. You need not drop (or remove) the time information. I have not tested for fractional seconds. However, if you have duplicates in the data column you may need to fix it and also you should correctly set the date format (YMD, DMY, etc.)
Here is a recent link to a correctly imported text file.
http://hodentekmsss.blogspot.com/2017/02/importing-text-file-into-ms-access.html
I had faced the same issue while importing CSV file with datetime. What I had done to solve this issue was by splitting date and time and merge.
Convert(varchar, yourdatecolum, 101 ) + ' ' + Convert(varchar, yourdatecolumn, 108)
The main problem is, that I have stored in database datetime , not the date (what I need). Ok never mind.
I have thousands of reports stored each day.
I need to LEFT by 10 my datetime_view (to cut the time) and everything's fine. Except this. I'm trying to figure out why do I have to put in the condition + one day from the future? Otherwise it won't search what I want.
SELECT
LEFT(datetime_view,10),
count(type)
FROM reports
WHERE
type IN (1,2,5)
AND
datetime_view>='2012-10-28'
AND
datetime_view<='2012-11-04'
group by LEFT(datetime_view,10);
You can see I must search from the future. Why??
It gives me an output from 28.10 to 3.11 ....
don't use string operations on date/time values. MySQL has a huge set of functions for date/time manipulation. Try
GROUP BY DATE(datetime_view)
instead, which will extract only the date portion of the datetime field. Your string operation is not y10k compliant. Using the date() function is.
As for your plus one day, consider how the comparisons are done: A plain date value, when used in date/time comparisons, has an implicit 00:00:00 time value attached to it, e.g. all dates have a time of "midnight".
i think it's better to use DATE(datetime_view) to cut the time instead of LEFT(datetime_view,10), also on the where condition:
DATE(datetime_view) <= '2012-11-03'