How can we convert YYYYWWD format date into normal date format YYYY-MM-DD? - mainframe

How can we convert YYYYWWD format date into normal date format YYYY-MM-DD using Syncsort?

I think you are out of luck. Syncsort has the same features as DF/Sort and according to this - https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.2.0/com.ibm.zos.v2r2.icea100/ice2ca_DFSORT_data_formats.htm - Df/sort does not recognise a YYYYWWD date format. It may be possible however to so the maths yourself with Syncsort, but I can;t see any way to do this.
YYYYWWD is a non-standard date format, so this is not really surprising. The best solution (if you cannot get the data in the correct format initially) would be to process the data with REXX before sorting it, if the volumes of data allows this.
Unless, of course, this is a 'homework' question and you have to use Syncsort? (which would imply that it is possible)

Related

How to parse string timestamp into date

I have a text value that looks like this: 2019-03-25T06:05:00-07:00. The general format is yyyy-mm-ddThh:mm:ss-GMT. I don't care about the GMT part. I am trying to use this text field to make time series scatter plots in excel.
I want to convert it to a timestamp as simply as possible. I currently do this using a bunch of formulas:
Input: 2019-03-25T06:05:00-07:00
Extract parts of time individually: =value(mid(input_cell,12,2))
Use date() and time() to get timestamp types
Add them together per this answer: https://stackoverflow.com/a/41164517/11163122
Use custom formatting to get a timestamp value
Output: 3/25/2019 6:05:00 AM
In total this took me 8 cells and custom formatting. This is too complicated. What is a simpler/more elegant way to do this?
You can use:
=--REPLACE(LEFT(A1,19),11,1," ")
and format as desired
Turns out the timestamp type is ISO 8601: https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations
This led me to this answer: https://stackoverflow.com/a/26315881/11163122
Using the formula there, I found this to be a sufficient solution. If anyone out there has a better method, please speak up! :)

Turn text with date to date type

I've searched on the internet and couldn't find. The only solution I found was to download kutools, and I can't do it.
I've made a macro that gets some values from an intranet, but I need the type of cell to be in date so I can work around it and filter it.
I don't know if I explained it correctly, and sorry if my english isn't the best.
I made an image to better explain it.
How it currently is / How I want it to be:
You can use the DATE and TIME functions to convert your text to date/time format.
=DATE(2018,MID(A2,4,2),LEFT(A2,2))+TIME(MID(A2,7,2),RIGHT(A2,2),0)
Using Filters:

VBA: proper date format to use

I have few cells where I fill date,and later I use these for calculations(substractions),so tell me which date format is good to use here. That should work for all regional languages and for all date separations like "-","/",".".Example - 12.1.2013.
I tried with -
//Format and Formatdatetime functions
Suggest me some answers please.
Thanks.
For universal dates I'd recommend one of three in order of my preference:
01-FEB-2013, as a format dd-mmm-yyyy
20130201, as format yyyymmdd
01022013, as a format ddmmyyyy

FIxing MS Excel date time format

A reporting service generates a csv file and certain columns (oddly enough) have mixed date/time format , some rows contain datetime expressed as m/d/y, others as d.m.y
When applying =TYPE() it will either return 1 or 2 (Excel will recognize either a text or a number (the Excel timestamp))
How can I convert any kind of wrong date-time format into a "normal" format that can be used and ensure some consistency of data?
I am thinking of 2 solutions at this moment :
i should somehow process the odd data with existing excel functions
i should ask the report to be generated correctly from the very beginning and avoid this hassle in the first place
Thanks
Certainly your second option is the way to go in the medium-to-long term. But if you need a solution now, and if you have access to a text editor that supports Perl-compatible regular expressions (like Notepad++, UltraEdit, EditPad Pro etc.), you can use the following regex:
(^|,)([0-9]+)/([0-9]+)/([0-9]+)(?=,|$)
to search for all dates in the format m/d/y, surrounded by commas (or at the start/end of the line).
Replace that with
\1\3.\2.\4
and you'll get the dates in the format d.m.y.
If you can't get the data changed then you may have to resort to another column that translates the dates: (assumes date you want to change is in A1)
=IF(ISERR(DATEVALUE(A1)),DATE(VALUE(RIGHT(A1,LEN(A1)-FIND(".",A1,4))),VALUE(MID(A1,FIND(".",A1)+1,2)),VALUE(LEFT(A1,FIND(".",A1)-1))),DATEVALUE(A1))
it tests to see if it can read the text as a date, if it fails, then it will chop up the string, and convert it to a date, else it will attempt to read the date directly. Either way, it should convert it to a date you can use

Best timestamp format for CSV/Excel?

I'm writing a CSV file. I need to write timestamps that are accurate at least to the second, and preferably to the millisecond. What's the best format for timestamps in a CSV file such that they can be parsed accurately and unambiguously by Excel with minimal user intervention?
For second accuracy, yyyy-MM-dd HH:mm:ss should do the trick.
I believe Excel is not very good with fractions of a second (loses them when interacting with COM object IIRC).
The earlier suggestion to use "yyyy-MM-dd HH:mm:ss" is fine, though I believe Excel has much finer time resolution than that. I find this post rather credible (follow the thread and you'll see lots of arithmetic and experimenting with Excel), and if it's correct, you'll have your milliseconds. You can just tack on decimal places at the end, i.e. "yyyy-mm-dd hh:mm:ss.000".
You should be aware that Excel may not necessarily format the data (without human intervention) in such a way that you will see all of that precision. On my computer at work, when I set up a CSV with "yyyy-mm-dd hh:mm:ss.000" data (by hand using Notepad), I get "mm:ss.0" in the cell and "m/d/yyyy hh:mm:ss AM/PM" in the formula bar.
For maximum information[1] conveyed in the cells without human intervention, you may want to split up your timestamp into a date portion and a time portion, with the time portion only to the second. It looks to me like Excel wants to give you at most three visible "levels" (where fractions of a second are their own level) in any given cell, and you want seven: years, months, days, hours, minutes, seconds, and fractions of a second.
Or, if you don't need the timestamp to be human-readable but you want it to be as accurate as possible, you might prefer just to store a big number (internally, Excel is just using the number of days, including fractional days, since an "epoch" date).
[1]That is, numeric information. If you want to see as much information as possible but don't care about doing calculations with it, you could make up some format which Excel will definitely parse as a string, and thus leave alone; e.g. "yyyymmdd.hhmmss.000".
"yyyy-MM-dd hh:mm:ss.000" format does not work in all locales. For some (at least Danish) "yyyy-MM-dd hh:mm:ss,000" will work better.
I believe if you used the double data type, the re-calculation in Excel would work just fine.
Go to the language settings in the Control Panel, then Format Options, select a locale and see the actual date format for the chosen locale used by Windows by default. Yes, that timestamp format is locale-sensitive. Excel uses those formats when parsing CSV.
Even further, if the locale uses characters beyond ASCII, you'll have to emit CSV in the corresponding pre-Unicode Windows "ANSI" codepage, e.g. CP1251. Excel won't accept UTF-8.
"yyyy-mm-dd hh:mm:ss.000" format does not work in all locales. For
some (at least Danish) "yyyy-mm-dd hh:mm:ss,000" will work better.
as replied by user662894.
I want to add: Don't try to get the microseconds from, say, SQL Server's datetime2 datatype: Excel can't handle more than 3 fractional seconds (i.e. milliseconds).
So "yyyy-mm-dd hh:mm:ss.000000" won't work, and when Excel is fed this kind of string (from the CSV file), it will perform rounding rather than truncation.
This may be fine except when microsecond precision matters, in which case you are better off by NOT triggering an automatic datatype recognition but just keep the string as string...
So, weirdly excel imports a csv date in different ways. And, displays them differently depending on the format used in the csv file. Unfortunately the ISO 8061 format comes in as a string. Which prevents you from possibly reformatting the date yourself.
All the ones the do come in as a date... contain the entire information... but they format differently... if you don't like it you can choose a new format for the column in excel and it will work. (Note: you can tell it came in as a valid date/time as it will right justify... if it comes in as a string it will left justify)
Here are formats I tested:
"yyyy-MM-dd" shows up as a date of course when opened in excel. (also "MM/dd/yyyy" works)
"yyyy-MM-dd HH:mm:ss" default display format is "MM/dd/yyyy HH:mm" (date and time w/out seconds)
"yyyy-MM-dd HH:mm:ss.fff" default display format is "HH:mm:ss" (time only w/ seconds)
As for timezones. I have to store the UTC offset as seconds from UTC that way formulas in Excel/OpenOffice can eventually localize datetimes. I found this to be easier than storing any number that has a 0 in front of it. -0900 didn't parse well in any spreadsheet system and importing it was nearly impossible to train people to do.
Try MM/dd/yyyy hh:mm:ss a format.
Java code to create XML file.
xmlResponse.append("mydate>").append(this.formatDate(resultSet.getTimestamp("date"),
"MM/dd/yyyy hh:mm:ss a")).append("");
public String formatDate(Date date, String format)
{
String dateString = "";
if(null != date)
{
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
dateString = dateFormat.format(date);
}
return dateString;
}
I wrote my timestamps to the CSV file as yyyy-mm-dd hh:mm:ss.
In Excel 365 I create a blank workbook, go to the Data tab and choose "From Text/CSV.
A dialog opens with a preview, which weirdly leaves the first column of timestamps alone, but shows it is going to convert the second column.
You can either "Load" the data, or "Transform Data", which is what I choose.
Now you're in the "Power Query Editor" and you can massage how Excel will bring the columns in.
In my case I undo any automatic changes it made, and tell it both columns are Data Type "Date/Time" using a little button on the ribbon.
Pressing Close & Load brings it into Excel as a data source that you can sort etc.
Given a csv file with a datetime column in this format: yyyy-mm-dd hh:mm:ss
Excel shows it in this format: dd/mm/yyyy hh:mm
e.g. 2020-05-22 16:40:55 shows as 22/05/2020 16:40
This is evidently determined by the Short date and Short time format selected in Windows; for example, if I change the Short date format in Windows to yyyy-mm-dd, Excel shows 2020-05-22 16:40.
Annoyingly, I can't find any way to make Excel show the seconds automatically (I have to manually format the column in Excel). But if the csv file includes a time column in hh:mm:ss format (e.g. 16:40:55), that's what shows in Excel, including the seconds.
I would guess that ISO-format is a good idea. (Wikipedia article, also with time info)

Resources