Problems with converting text to date (YYYY-MM-DD) in Excel (Mac) - excel

I have been able to convert this date to YYYY-MM-DD HH:mm but not anymore. What can I do to convert this date.
Sep 15, 2014 9:30:32 AM
You need to know that I'm using Swedish keyboard, date and region.
Example:
Order # Purchased On
100026881 Sep 15, 2014 9:30:32 AM
100026880 Sep 15, 2014 9:10:56 AM
100026879 Sep 15, 2014 9:09:10 AM
100026878 Sep 15, 2014 9:03:27 AM
100026877 Sep 15, 2014 8:57:02 AM
100026876 Sep 15, 2014 8:38:37 AM
100026875 Sep 15, 2014 6:54:29 AM
100026874 Sep 15, 2014 5:03:23 AM
100026873 Sep 15, 2014 2:45:50 AM
100026872 Sep 15, 2014 1:42:26 AM
100026871 Sep 14, 2014 11:20:31 PM
100026870 Sep 14, 2014 11:16:29 PM
100026869 Sep 14, 2014 11:11:15 PM
100026868 Sep 14, 2014 11:10:06 PM
100026867 Sep 14, 2014 10:42:56 PM
100026866 Sep 14, 2014 10:41:22 PM
100026865 Sep 14, 2014 10:36:43 PM
100026863 Sep 14, 2014 10:26:13 PM

Formatting a date in Excel 2011 for Mac
You have at least three different ways to apply a date format. Perhaps the fastest is to select a cell or cell range, and then click the Home tab of the Ribbon. In the Number group, click the pop-up button under the Number group title and choose Date to display the date as m/d/yy, where m represents the month's number, d represents the day number, and yy represents a two-digit year.
Excel has many more built-in date formats, which you can apply by displaying the Format Cells dialog by pressing Command-1 and then clicking the Number tab. You can also display the Number tab of the Format Cells dialog by clicking the Home tab on the Ribbon. Then click the pop-up button under the Number group title and choose Custom from the pop-up menu.
When the Format Cells dialog displays, select the Date category. Choose a Type from the list. Choosing a different Location (language) or Calendar type changes the date types offered.
I hope this may helps..

This should be a comment since I have neither Swedish settings not a Mac but I am suggesting a lookup table:
+-----+----+
| Jan | 1 |
| Feb | 2 |
| Mar | 3 |
| Apr | 4 |
| May | 5 |
| Jun | 6 |
| Jul | 7 |
| Aug | 8 |
| Sep | 9 |
| Oct | 10 |
| Nov | 11 |
| Dec | 12 |
+-----+----+
say named Marray, along with:
=TEXT(DATE(MID(B2,9,4),VLOOKUP(LEFT(B2,3),Marray,2,0),MID(B2,5,2))+VALUE(TRIM(RIGHT(B2,11))),"[$-41D]mmmm dd, yyyy h:mm:ss AM/PM")
in C2 and copied down to suit (assuming Sep 15, 2014 9:30:32 AM is in B2).
For single digit dates, perhaps:
=TEXT(DATE(TRIM(MID(B2,8,5)),VLOOKUP(LEFT(B2,3),Marray,2,0),SUBSTITUTE(TRIM(MID(B2,4,3)),",",""))+VALUE(TRIM(RIGHT(B2,11))),"[$-41D]mmmm dd, yyyy h:mm:ss AM/PM")
For me (Windows, Excel 2013, English!) this returns:
It may be necessary to replace all ,s with ;, except one inside SUBSTITUTE.

I think that Jeeped might be close to the problem.
My guess is that now the data may have been pasted as text, instead of recognizing the date. (pnuts had an answer but it's a lot more work than using the builtin Excel functions.)
If the dates are in their own column, like:
Sep 15, 2014 9:30:32 AM
Sep 15, 2014 9:10:56 AM
Sep 15, 2014 9:09:10 AM
etc
Then you might have to get Excel to parse the text dates.
If the date text is in B2, put this formula in another cell (say B3):
=DATEVALUE(B2) + TIMEVALUE(B2)
Then you can format with this custom formatting string: yyyy-mm-dd h:mm:ss AM/PM
Which will give you:
2014-09-15 9:30:32 AM
2014-09-15 9:10:56 AM
2014-09-15 9:09:10 AM
etc.
Hope this helps.

Related

Splitting datetime value out of text string with uneven length

System: WIN10
IDE: MS Visual Studio COde
Language: Python version 3.7.3
Library: pandas version 1.0.1
Data source: supplied in the example below
Dataset: supplied in the example below
Ask:
I need to split the date and time string out of a column from a data frame that has rows of uneven delimiters i.e. some with three and some with four commas.
I am trying to figure out how to strip the date and time values: 'Nov 11 2013 12:00AM', and 'Apr 11 2013 12:00AM' respectively off the back of these two records in one column into a new column given the second row in the example below has fewer commas.
Code:
df['sample field'].head(2) 
4457-I need, this, date, Nov 11 2013 12:00AM ,
2359-I need this, date, Apr 11 2013 12:00AM , 
While the below method expands the data into different columns and staggers which column houses the date, this does not work. I need the date and time (or even just date) information in one column so that I can use the date values in further analysis (for example time-series).
Code:
df['sample field'].str.split(",", expand=True)
Data
df=pd.DataFrame({'Text':['4457-I need, this, date, Nov 11 2013 12:00AM ,','2359-I need this, date, Apr 11 2013 12:00AM ,']})
df
Use df.extract with a regex epression
df['Date']= df.Text.str.extract('([A-Za-z]+\s+\d+\s+\d+\s+\d+:[0-9A-Z]+(?=\s+\,+))')
df
#df.Date=pd.to_datetime(df.Date).dt.strftime('%b %d %Y %H:%M%p')
#df['date'] = pd.to_datetime(df['date'] ,format='%b %d %Y %H:%M%p')
df['Date']=pd.to_datetime(df['Date'])#This or even df['Date']=pd.to_datetime(df['Date'], format=('%b %d %Y %I:%M%p')) could work. Just remmeber because your time is 12AM use 12 clock hour system %I not %H and also hour 00.00 likely to be trncated, If have say11.00AM, the time will appear
IIUC you need str.extract with a regular expression.
Regex Demo Here
print(df)
0
0 4457-I need, this, date, Nov 11 2013 12:00AM
1 2359-I need this, date, Apr 11 2013 12:00AM
df['date'] = df[0].str.extract('(\w{3}\s\d.*\d{4}\s\d{2}:\d{2}\w{2})')
df['date'] = pd.to_datetime(df['date'] ,format='%b %d %Y %H:%M%p')
print(df)
0 date
0 4457-I need, this, date, Nov 11 2013 12:00AM 2013-11-11 12:00:00
1 2359-I need this, date, Apr 11 2013 12:00AM 2013-04-11 12:00:00
I'll use #wwnde's data :
df=pd.DataFrame({'Text':['4457-I need, this, date, Nov 11 2013 12:00AM ,','2359-I need this, date, Apr 11 2013 12:00AM ,']})
df['Date'] = df.Text.str.strip(',').str.split(',').str[-1].str.strip()
df['Date_formatted'] = pd.to_datetime(df.Date, format = '%b %d %Y %H:%M%p')
Text Date Date_formatted
0 4457-I need, this, date, Nov 11 2013 12:00AM , Nov 11 2013 12:00AM 2013-11-11 12:00:00
1 2359-I need this, date, Apr 11 2013 12:00AM , Apr 11 2013 12:00AM 2013-04-11 12:00:00

Calculate difference between dates in months and based on defined deadline MS EXCEL

everyone. I am trying to get the difference between two dates in Excel based on a defined deadline which is the 10th the following month. Please see sample below.
Month | Deadline | Date Paid | Month/s Elapsed | Remarks
Jan 2020 | Feb. 10, 2020 | Feb. 10, 2020 | 1 | One 10th has passed
Jan 2020 | Feb. 10, 2020 | Mar. 13, 2020 | 2 | Two 10th have passed based on Date Paid
Mar 2020 | Apr. 10, 2020 | Jun. 27, 2020 | 3 | Three 10th have passed from Mar 2020 - June 27, 2020
Basically, should the Date Paid fall beyond the 10th of the following month, it should count how many 10ths have elapsed from the deadline to the date paid. Here is my formula so far and it's not taking into account the deadline which is the 10th every month.
=MONTH(c2)-MONTH(B2)
Could you kindly provide any ideas as to how I can achieve the expected output?
I hope my question is clear. Thank you in advance for your help.
In your current setup it looks like you could just use:
=DATEDIF(B2,C2,"M")+1
Not sure if that would be error-proof for all your cases. The following should return the amount of dates in an array that are equal to the 10th of that month:
=SUMPRODUCT(--(DAY(ROW(INDEX(A:A,A2):INDEX(A:A,C2))=10))
This is with the assumption that column A holds dates that are the last days of those months!

Conditional Cumulative Sum based on multiple columns

I have a simple inventory table in excel that looks like this:
Number of Items | Date Incoming | Date Out
-------------------------------------------------------
10 | 1 Jan 2018 | 30 Jan 2018
30 | 15 Jan 2018 | 1 May 2018
20 ! 1 Feb 2018 | 15 Mar 2018
I would like something that can give me the the total number of items that are present in the inventory at each date, that is:
1 Jan 2018 | 10
15 Jan 2018 | 40
30 Jan 2018 | 30
1 Feb 2018 | 50
15 Mar 2018 | 30
1 May 2018 | 0
What I was thing is some sort of cumulative sum where the number of items are added at "Date Incoming" and substracted at "Date Out".
Can you help me? I would prefer to avoid macros but even a vba solution if fine.
For a given date, you can do:
=sumif(#DateIn, "<="&#CellWithGivenDate, #NumberOfItems) - sumif(#DateOut, "<="&#CellWithGivenDate, #NumberOfItems)
With #NumberOfItems, #DateIn, and #DateOut being columns 1 to 3 of your sample, and #CellWithGivenDate being the relevant cell in column 1 of your expected result sample.

Excel Offset Subtraction Inside Cells?

I have thousands of rows of these two columns worth of data that looks exactly to this. The date and time of an event is listed inside a single cell. I need to be able to subtract the time in one cell from the other, but I'm not sure exactly how to go about doing this.
For instance, I would need to somehow pull 4:00am and subtract the difference of 6:00am - leaving me an answer of 2 hours. Thank you ahead of time!
Nov 25, 2016 4:00:00 AM Nov 25, 2016 6:00:00 AM
Nov 25, 2016 4:00:00 AM Nov 25, 2016 6:00:00 AM
Nov 25, 2016 4:00:00 AM Nov 25, 2016 5:15:00 AM
Nov 25, 2016 4:00:00 AM Nov 25, 2016 6:00:00 AM
Nov 25, 2016 4:00:00 AM Nov 25, 2016 6:00:00 AM
In C1:
=24*(B1-A1)
and fill down.
Dates in Excel are managed such that subtracting A1 from B1 gives a fraction of a day, so multiply by 24 to get number of hours.

Excel:Next year period

How to get next year period based on current month and year, for example:
Jan 2014 - Dec 2014
Feb 2014 - Jan 2015
Mar 2014 - Feb 2015
Apr 2014 - Mar 2015
May 2014 - Apr 2015
Jun 2014 - May 2015
Jul 2014 - Jun 2015
Aug 2014 - Jul 2015
Sep 2014 - Aug 2015
Oct 2014 - Sep 2015
Nov 2014 - Oct 2015
Dec 2014 - Nov 2015
Next period
Jan 2015 - Dec 2015
Feb 2015 - Jan 2016
etc.
I have tried with the following formula:
=UPPER(TEXT(NOW();"MMM")) &" "& TEXT(NOW();"YY")-1
It works fine for Jan 2014 but can't figure out how to get Dec 2014; Feb 2014 - Jan 2015 and so on?
I think you need the EOMonth formula.
=EOMONTH(NOW(),-13) +1 and =EOMONTH(NOW(),-2) +1 should give give you JAN 2014 to DEC 2014
from the MS Excel documentation
Microsoft Excel stores dates as sequential serial numbers so they can
be used in calculations. By default, January 1, 1900 is serial number
1, and January 1, 2008 is serial number 39448 because it is 39,448
days after January 1, 1900.
To get the text formatting you are after, I would suggest that you stick with formatting the cell/column as #Makyen has suggested. Having said that this is the formula that you can use to format the text.
=UPPER(TEXT(EOMONTH(NOW(),-13) +1, "MMM YY"))
Assuming that the date (as a date serial number) for which you desire to find the year period is in cell A1, the following should provide the next year period starting from that day:
=EOMONTH(A1,11) +DAY(A1) -1
Examples:
Input Output
1/18/2014 1/17/2015
2/18/2014 2/17/2015
3/18/2014 3/17/2015
4/18/2014 4/17/2015
5/18/2014 5/17/2015
6/18/2014 6/17/2015
7/18/2014 7/17/2015
8/18/2014 8/17/2015
9/18/2014 9/17/2015
10/18/2014 10/17/2015
11/18/2014 11/17/2015
12/18/2014 12/17/2015
1/18/2015 1/17/2016
2/18/2015 2/17/2016
3/18/2015 3/17/2016
4/18/2015 4/17/2016
5/18/2015 5/17/2016
6/18/2015 6/17/2016
7/18/2015 7/17/2016
8/18/2015 8/17/2016
9/18/2015 9/17/2016
10/18/2015 10/17/2016
11/18/2015 11/17/2016
12/18/2015 12/17/2016
1/18/2016 1/17/2017
If you want the year period to start from the current day:
=EOMONTH(NOW(),11) + DAY(NOW()) -1
If you want the year period to start from the first day of the current month:
=EOMONTH(EOMONTH(NOW(),-1) + 1,11)
or
=EOMONTH(NOW() - DAY(NOW()) + 1,11)
The EOMONTH() function:
EOMONTH(start_date,months)
Returns the serial number for the last day of the month that is the
indicated number of months before or after start_date. Use EOMONTH to
calculate maturity dates or due dates that fall on the last day of the
month.
If this function is not available, and returns the #NAME? error,
install and load the Analysis ToolPak add-in.

Resources