Raw Excel Data contains different Date formats - matlab

I have huge amounts of raw data that are separated by columns. All is well when i import these to Matlab except for the fact that I just saw that the excel files contains different formats for the dates.
One series (i.e 3 days, 1 row or each hour gets 3x24 rows) have its' dates in the format "mm/dd/yyyy" which neither excel or matlab recognizes as proper dates.
I've tried solving this problem in different ways. First i tried to just highlight the cells and use the function format cells, but this didn't work since excel doesn't see them as 'cells' but rather as 'text'.
Then i tried the Text to columns function which didn't work either (delimited or fixed width).
Im really stuck and would appreciate some help with this.

In Excel:
If cell A1 has a string like mm/dd/yyyy then try this:
=DATE(RIGHT(A1,4), LEFT(A1,2), MID(A1,4,2))
In Matlab:
=datenum(yourDateString, 'mm/dd/yyyy')

Select the desired range to fix and use this script:
Sub bulk_Date_fix()
on error resume next
Set d_ranged = Selection
For Each a In d_ranged
a.Value = Split(a.Value, "/")(0) & "/" & Split(a.Value, "/")(1) & "/" & Split(a.Value, "/")(2)
Next
on error goto 0
End Sub
How it works: The above script loops through all the cells in the selected area and splits out the various attributes of a date based on the "/" symbol.

I examined your file and you will need to go back to the source data to straighten this out. Instead of "opening" the file in Excel, you will need to IMPORT the file. When you do that, the text import wizard will open, and you can then designate the date column as being of the format DMY (or whatever format is being generated by the source).
The problem is that there is a mismatch between the format of the file, and your Windows Regional Short date format. If you look at Row 229, you will see that real dates are present, but out of sequence with the rest.
Excel parses dates being input according to the Windows Regional Short Date settings. If the date doesn't make sense, according to that parsing (e.g. month > 12) , Excel will interpret the date as a string; if the date does make sense, it will be interpreted as a date in accordance with that windows regional date component order, and this will be different from what is intended.
So the first few hundred dates are strings, but at line 229, the date, which is probably meant to be 12 OCT 2014, gets changed to 10 DEC 2014. This will happen in other areas where that value in the 2nd position is 12 or less.
EDIT: I am not certain of the variabilities inherent in using XL on the MAC. In the Windows version of XL, the "text import" feature is on the Data Ribbon / Get External Data Tab:
When you click on that and open a text file, you will see the Text Import Wizard, and when you get to Step 3, you will be able to specify the text format of the data to be imported:

Related

Date issues in Google sheets

I have some dates in Text format and some other in Date format.
I tried so many things to reconvert them in proper format. DD/MM/YYYY
16/10/2022
05/12/2023
24/05/2023
I still cant figure out. They all looks in Date format but some are not. How i can re-format properly. There is sample of my dates.
https://docs.google.com/spreadsheets/d/1aNsoqXnpNkQs7LloFuHVObARqI2QEh5X8ClCu42ICyQ/edit?usp=sharing
How i can fix this?
Here's what happened :
you had a bunch of dates formatted as DD/MM/YYYY and pasted them and they were automatically parsed in the format MM/DD/YYYY leading some of them being recognized as proper dates (but not the ones you intend to have), and some of them being leaved as text.
To solve this you can copy paste the column in a text file, then import this file; when you import the data in excel, use the "text to columns" to choose the date format.
You can also change your locale date settings.
Last solution that does not involve creating a new file : copy paste your dates in a text file, add a ' in front of each line which ensures the cell content is not automatically interpreted, then parse the date from this text using the formula :
=date(right(H2,4),mid(H2,4,2),left(H2,2))
(if your text is in h2)
One last thing : some of your data in the left column is not in the correct format. You probably have a formatting problem / data quality problem in the source data you copy/pasted from.
save file in CSV or convert to csv
Open as text
Use the Text import wizard from paste

Google Sheets - Concatenate NOW-1, slash, and NOW+120

In Google Sheets, I need to create a date in the following format:
2016-06-15T12:00-0800/2016-10-16T12:00-0800
(Yesterday's date / today's date + 120 days)
Using =NOW()-1, I get yesterday's date.
Using Format - Date - More - Year(1930)-Month(05)-Day(01)T:Hour(01):00-0800, I get the proper format for the 1st part of the date range (2016-06-15T12:00-0800).
Repeating the same process with =NOW()+120.
Got the 2nd part of the date range (2016-10-16T12:00-0800).
PROBLEM: Trying to =CONCATENATE(A2,"/",B2), results in this:
42901.6965777315/43022.6965777315
...and no matter what I do - change the format, try to use =CONCATENATE(=TEXT(A2),"/",=TEXT(B2)), or other tricks I know, I either get a blank cell, an error message, or an even worse mess.
All I want is to combine 2 date cells into 1, with a slash in between. How can this be accomplished?
Try join instead of concatenate:
=join("/",A1,B1)
Maybe:
=text(now()-1,"yyyy-mm-ddThh:mm")&"-0800/"&text(now()+120,"yyyy-mm-ddThh:mm")&"-0800"
TEXT with only a date as argument returns the serial number corresponding to that date,
First you should confer the result of you formulas that involves NOW to a formatted text by using TEXT with the second argument. Then you could concatenate the result of that.
The above be donde on a single formula but you maybe should start by doing each step on separate cells in order to make it easy to check the result of each part.

Convert text date format to number date format

I have stored some data entrys in a CSV file in following Format:
Thu Jul 28 08:42:33 GMT+01:00 2016
and need to convert it to just a time stamp (eg. h:m:s). How can I quickly and easily do this?
To convert a text date in a cell to a serial number, you use the DATEVALUE function. Then you copy the formula, select the cells that contain the text dates, and use Paste Special to apply a date format to them. Select a blank cell and verify that its number format is General.
If the size is fixed, then assuming the string is in A1:
=MID(A1,12,8)
The result can then be converted to an actual time value using TIMEVALUE.
Looks like a simple call to a single function would extract the substring you want, since it begins at a specific offset and only runs for eight characters (two hh plus colon plus two mm plus colon plus two ss).

Short date style input mask txt showing as plain string in MS Access 2013

I have an text entry control with the input mask 00/00/0000. However it comes into the data table as just a string of numbers, e.g. 05132015. I have the datatype in the schema set to short text with a format of mm/dd/yyyy. Actually, I don't understand the difference between the format (set in the table design mode) and the input mask. Just my ignorance. I don't have a short date data type in the drop down list. In short, I want to have the user enter a short date in the format mm/dd/yyyy and have it show up in the datasheet view with the slashes.
Edit:
I'm having the same problem with running times with an input mask 00:00:00.
Edit:
I found out that I can specify shortened versions of the DateTime datatype. That will do the trick. However, in the short term, is there a way to use an input mask and still have the delimiter come through?

Generating OpenXML Excel file doesn't apply date formatting [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Open Xml and Date format in Excel cell
I'm trying to take data from a DataGridView and generate an Excel file with the contents. I have a problem with dates though.
The problem is that, having written the worksheet, saved and opened it in Excel, my date cell has a date value in it and, if I do "Format cells", has the format I requested, yet Excel hasn't applied that format. For example, if I export the date value using ".ToOADate()", I get something like "40690.5270454051" in the cell. If I click into the cell, and then out again, the correct formatting is applied.
I've tried omitting the "ToOADate" call, and the same thing happens (I get a recognisable date value, but only formatted using my custom format after I click in and out of the cell).
I've tried setting the DataType of the OpenXml.Spreadsheet.Cell object to CellValues.Date (or EnumValue(CellValues.Date)) but then I get an error about "unreadable content" when I try and open the xlsx file.
Thanks,
Ross
What you need to do is set a value that is a floating point number (number of days since Jan 1, 1900 or 1904 - there is a setting in the file to decide which). The hh:mm:ss is the fraction part of the number.
You then set the cell format to be the datetime format you want. Excel will then display the number as the formatted date. This is how Excel stores all dates.
What I think is happening in your case is you are setting the value to a string. When you click on the cell, Excel parses the string, sees that it can be turned into a date, and then saves it as the floating point value.
Save the file after clicking and then look at the cell contents to see the difference.