I have a spreadsheet I need to make in Google Sheets. The source of some of the data is exported to an Excel sheet. The data arrives in a dd/mm/yyyy format and I need to display it in a MON d format (Ex Sep 5).
The problem is both excel and sheets look at the date that arrives and think it is mm/dd/yyyy.
For example, 02/08/2022 is believed to be Febuary 8 even though it should be Aug 2. The problem then arises that neither of these platforms end up knowing how to convert this to Aug 2 and I end up having to do this manually.
Does anyone know how to get around this?
I have tried adjusting the format of the date, as well as using DateValue to convert (this fails since it understands the date as mm/dd/yyyy even when it is dd/mm/yyyy).
Any leads would be appreciated!
Thanks!
In Google Sheets, choose File > Settings > Locale and select a locale that uses the dd/mm/yyyy date format, before importing the data. You can then format the date column the way you prefer.
in gs:
=TEXT(REGEXREPLACE(A1&""; "(\d+)\/(\d+)\/(\d+)"; "$1/$1/$3"); "mmm d")
Try the following and format the result to your liking
=INDEX(IF(ISNUMBER(U2:U5),U2:U5,
IF(U2:U5=DATEVALUE("1899-12-30"),,
(MID(U2:U5,4,3)&LEFT(U2:U5,3)&RIGHT(U2:U5,4))*1)))
(Do adjust the formula according to your ranges and locale)
Functions used:
INDEX
IF
DATEVALUE
ISNUMBER
TRUNC
MID
LEFT
RIGHT
Well, for a formulaic solution, if the date is in A1, then the following places the correct date in B1:
=DATEVALUE(TEXT(A1,"DD/MM/YYYY"))
The TEXT function makes a string that will be the same form as your imported string out of the date produced during import. DATEVALUE then gives the proper date you desired.
The trick is in the TEXT step in which you reverse month and day in the string for DATEVALUE.
Naturally, instead of a helper column, it could just be wrapped around any reference to a date from column A, though one would have to remember to do so for all the years the spreadsheet is in use.
If you are importing, not just opening a .CSV file via File|Open and going from there, you have an opportunity to solve all your problems. You use the Ribbon menuing system's Data menu, select the very leftmost thing, Get Data and from the (no arguing THIS isn't a menu) menu that drops down, Legacy Wizards, then finally From Text (Legacy) which will open the old Excel Import Wizard. (You may notice this is very like the Data|Text to Columns Ribbon menu choice and that is because that choice is the old wizard minus the steps at the start that go looking to another file for the data because it knows, by law, that it has to already be in the spreadsheet... in other words, it looks the same because it IS the same.)
Then make selections for the first couple dialogs it presents you to get to the dialog in which you tell it to import columns as whatever: general (let Excel decide), text, date, and do not import. Choose Date and make the selection of DMY to import them properly as you desire them to be so you are never presented with the problem at all.
As you might guess, you can use the abbreviated wizard via the "Text to Columns" feature to do the same thing after import when you see they are reversed. Since it is a single column of data, the result will overwrite the original simplifying your work.
Why does this happen at all? Well, the "locale" folks have the idea. When Excel imports numbers that are in a form it recognizes could be a date, it looks to the operating system settings for the selected ways dates are understood. So if your operating system believes a date should be displayed "Month Day, Year" and Excel has a set of data it thinks fits that mold, it will convert them all using it. So you get those Feb 8's rather than Aug 2's.
Interestingly, it does two other things of note:
It looks at 8, count 'em, 8 rows of data to decide the data fits the pattern. Even with 1,000,000 rows to import, it looks at... 8.
Then it does them ALL as if God himself wrote the "8"... and dates like 25/03/2022 get imported as text not a real date, because they (oh, obviously) can't be dates... "25" can't be a month!
It IS possible to change settings (DEEP settings) to make Excel consider X number of rows in a data set before deciding such things. I found them here, on the internet, once upon a time, though I shouldn't like trying to find them again. It will consider up to a million rows in such an import, but... that'd make it pret-ty slow. And that's a million rows for EACH data column. I won't even say that "adds up" - I'll point out it "multiplies up."
Another technique is to add some number of starting rows to force the desired pattern onto the import. I've heard it works in TIME column imports so it ought to in DATE column imports but I've not verified such.
My bet is you will find the use of the "Text to Columns" feature of most use if you can use a hands-on approach - it does require literal action on your part, but is a fast operation. If you will see others using the spreadsheet though... well, you need a formulaic solution or a VBA one (macro with button for them to have some fun clicking as their reward for doing what they were trained to do instead of complaining to the boss you make bad spreadsheets). For a formulaic solution, the above formula is simple.
Last thought though: there's no error-checking and error-overcoming in it. So a date like "25/03/2022" in the data that imported as literal text is a problem. For handling the latter, an up-to-date approach could be:
=IF(TYPE(A1)=1,DATEVALUE(TEXT(A1,"dd/mm/yyyy")),DATE(INDEX(TEXTSPLIT(A1,"/"),1,3),INDEX(TEXTSPLIT(A1,"/"),1,2),INDEX(TEXTSPLIT(A1,"/"),1,1)))
in which the DATE(etc. portion handles finding text of the "25/03/2022" kind. Lots of less up-to-date ways to split the text Excel would have placed in the column, but since demonstrating what to do if it existed was the point, I took the easy way out. (Tried for a simple version but it wouldn't take INDEX(TEXTSPLIT(A1,"/"),1,{3,2,1}) from me for the input parameters to DATE.) TYPE will give a 1 if Excel imported a datum as a date (number), and a 2 if brought in as text. If empty or strange strings could exist, you'll need to deal with what those present you as well.
Problem
I'm trying to accurately represent a date from Google Sheets in a DataFrame. I know that the "base" dates in Google Sheets are integers added to the date since 1/1/1900. Testing this is clear: I have a Sheet with the date 5/2/2019. Using the Python API, I download this Sheet with the parameter valueRenderOption='UNFORMATTED_VALUE' to ensure I'm getting raw values, and do a simple conversion to a DataFrame. The value shows up as 43587, and if I put that back into a Sheet and set the format to date, it appears as 5/2/2019. Sanity check complete.
The problem arises when I try to convert that date in the DataFrame to an actual datetime: it shows up as offset by two days, and I'm not sure why.
Attempts
In a DataFrame df, with datetime column timestamp, I do the following:
df['timestamp'] = pd.to_datetime(df['timestamp'], unit='d', origin='1900-01-01')
and I get a date of 2019-05-04, which is two days later than I would expect. I searched for this on SO and found a similar issue, but the accepted answer actually contains the exact same problem (albeit no mention of it): a two day offset.
This can be "solved" by setting the origin two days back, to 1899-12-30, though that feels almost like a cover, and not necessarily fixing the underlying issue (and could perhaps leads to further date inconsistencies down the road as more time has passed?).
Here's code for a toy DataFrame so that you don't have to type it out, if you want to experiment:
import pandas as pd
df = pd.DataFrame([{'timestamp': 43587}])
Question
I imagine this is on the Pandas side of things, but I'm not sure. Some internal conversion that happens differently than how they do it at Google? Does anyone have an idea of what's at play here, and if setting the origin date two days earlier is actually a solution?
I have been banging my head against this as well, and think that I finally figured it out. While for the Date() function, Sheets uses 1900-1-1 as the base, for the date format and for the TO_DATE() function, the origin date is 1899-12-30.
You can see this in Sheets by either
entering 0 in a cell, and then formatting to a date → 12/30/1899
entering =TO_DATE(0), which will result in 12/30/1899
One origin story for this odd choice is here in a very old MSDN forum. I have no idea of its veracity.
At any rate, that explains the two-day discrepancy and then the solution becomes
df['timestamp'] = pd.to_datetime(df['timestamp'], unit='d', origin='1899-12-30')
which worked for me.
I'm trying to design a Microsoft Flow, which will create a outlook calendar event entry based on information in a SharePoint-online list.
The list will contain a value for a DueDate its a column of type Date, not including time.
I want to be able to create a outlook calendar entry on the date based off the duedate column. The calendar entry form in flow allows via dynamic content to add dates that also include time, however date columns not containing time cannot be added that way.
Is there a workaround to this, some expression that would allow me to fetch values from columns more freely and then possible append a time to it
I have tried converting the column in sharepoint to a Date with Time column and that workaround worked, however its not what I'm looking for. Id like to know how to be able to work around this because I don't necessarily want my column as a date-time column which can cause problems later on.
I have tried this expression:
formatDateTime(concat(item()?['DATE'], '08:00')'yyyy-MM-ddThh:mm:ss')
But I know this is wrong and it doesn't work. I'm simply not sure how to do it.
https://puu.sh/Df5ni/05cb882b23.png
I want the flow to add a calendar entry based off the due date column which i can append my own time to like the start of the day and last til the afternoon.
Actual results are I don't seem to be able to use a date column, just a date-time column for start and end times of the event, date column without time doesnt appear in the dynamic content list.
If there is some way to manually fetch values instead of using the dynamic content that is very powerful and can then possibly be converted to the right format using additional code.
Date column name in my list is date_without_time of type Date (Add time set to NO):
New element:
Function used in Create event (V2) action:
formatDateTime(triggerBody()?['date_without_time'],'yyyy-MM-ddT09:35')
Result:
Calendar:
I was taught how to convert a date-as-string value that was being converted from what I wanted ("Sep 2015", "Oct 2015" etc.) to what Excel thought it should be ("15-Sep", "15-Oct" etc.) here.
When it was displaying "badly," the columns at least displayed in the right order ("2015-Sep" followed by "2015-Oct"). Now that they are "Sep 15" and "Oct 15", though, they are displaying out of "natural" order and in alphabetical order ("Oct 15" followed by "Sep 15").
This is the too-typical scenario (especially egregiously evident in software development) of the solving of one problem causing another one to rear its ugly rear.
This is how I create the "month" part of the PivotTable:
var monthField = pvt.PivotFields("MonthYr");
monthField.Orientation = XlPivotFieldOrientation.xlColumnField;
Before fixing the display format problem:
After fixing the display format problem ("15-Sep" is now "Sep 15", etc., but the months are now out of order):
Can I "have my cake and eat it, too" so to speak? If so, how?
From reading the comments, it sounds like you need to convert your C# date to an excel date. In the second comment you mention that you were able to get values "201509" and "201510" onto an excel sheet.
I suggest you separate the year and month using the LEFT() and RIGHT() functions, then use the DATE() function to get the Excel serial number for 9/1/15 and 10/1/15.
Here's a screenshot of the steps I'm think of (Happy Halloween!):
Finally, you can now format the Serial number using your formula monthField.NumberFormat = "MMM yy". Excel will realize this is a date and sort it chronologically.
I am trying to code a date function in Excel using the Month and than the last two digits of the year. So for example I just have the numbers 1-12 in a column. Then I want to code them as follows. 1 is Jan-15, 2 is Feb-15,..June-15. Then 7 is July-14, 8 is Aug-14. However whenever I try to type in those it codes them as their respective month, the day and the year as 2015. I know I have to create a custom format date function, but how would I go about doing that in this case. I have seen some things, but many of times it is unclear. Could Someone help me out.
This link can help you out.
Create a custom date format
If you want to use a format that isn’t in the Type box, you can create your own. The easiest way to do this is to start from a format this is close to what you want.
Select the cells you want to format.
Press CTRL+1.
In the Format Cells box, click the Number tab.
In the Category list, click Date, and then under Type, pick a date format that is close to the format you want.
Go back to the Category list, and pick Custom. Under Type, you’ll see the format code for the date format you picked in step 4. The built-in date format can’t be changed, so don’t worry about messing it up. The changes you make will only apply to the custom format you’re creating.
In the Type box, make the changes you want using code from the table below.
According to the table there and your description I suppose you should use a custom format like:
mmm-yy