Excel Date Formatting is Being Changed from Date to General on Moblie Preview - excel

So we have a weekly report that gets sent out. In the report there are dates assigned to production numbers and for some reason when previewed from a mobile device the dates are changed to integers. 43028 is October 20, 2017. I have no idea where this number is coming from, because this goes back to December 30, 1899. I have no idea why it's switching into this form and only on mobile devices.

This is how excel handles dates. The integer represents a count from a set date (you can enter 0 into a cell and format it as a date to find the starting date). Every +1 represents the next day from that starting point. Your decimals represent hours (.5 = half day).
You can try a helper column and set it equal to your date using =TEXT(A2,"m/dd/yyyy") where A2 is your current date. Date format can be adjusted to taste.

Related

Difference between date and time w/out work week Excel

I am trying to determine the amount of time a procedure takes. I have the Start Date and Start Time as well as End Date and End Time. What I need to do is display the result in hours:minutes:seconds BUT I need to use a 7 day work week rather than a 5 day work week. Here is a sample data point:
Cell A1 and C1 are both formatted as short dates. Cell B1 and D1 are formatted as times. The formula in E1 is =((C1+D1)-(A1+B1)) and E1 is formatted as a custom number [h]:mm:ss . The problem I am having is calculating through a weekend. The times just don't add up and I think it is because of the type of work week that Excel uses.
Any help is appreciated, thanks!
First, you need to know / understand that any number is a potential date / time for Excel and that Excel knows only datetime (and not date and time separately).
Here is why: anything before the decimals-placeholder are the days since December 31, 1899. So, the number 42,000.00 is also a date. It is the 42.000th day after December 31, 1899 which is December 27, 2014.
Anything after the decimal-placeholder is considered a fraction of a day. So, the value 0.5 is half a day and therefore the time 12 noon while 0.75 is 6 in the afternoon (pm).
Hence, all of the dates you are showing in your above examples may have also times associated with them and all the times you are showing might also have a date associated to them. Just change the number format on all of these cells to general numbers and you should see only Integer values for the dates (without any decimal places) while all the times should contain only be a fraction of 1 and should all have a 0 before the decimal-placeholder.
If that is not the case, then you have just found your culprit.
With the above knowledge it is also easy to calculate the difference between two dates or times. The difference is a simple addition or subtraction: 42,000.00 + 100 + 0.5 = 100 days after December 27, 2014 at 12 noon = April 6th, 2015 # noon. So, you can just add the numbers and subtract them as you have done. If you wish to subtract two days to account for a weekend then you can simple subtract 2.
Now, let's have a look at your above example:
June 23, 2016 converts to 42,544 while 07:41 in the morning converts to 0.32. So, we have here 42,544.32 while the ending datetime converts to 42,545.47.
The difference is calculated correctly as 1.15. That means that there is a difference of one day and the fraction of a day of 0.15 * 24 (hours in a day) = 3 hours and 36 minutes.
I guess the real problem you are having is to show the result correctly. If you show it as a date then it is one day after December 31, 1899 = January 1st, 1900. If you show the result as a time then you only get to see the 03:36:00. The best is probably to show the difference as a number only as 1.15. If you want to see the result differently then you will have to adjust the resulting view to your needs. For example:
= 1.15 * 24 = 27.6 hours difference between the start date/time and the end date/time.
Let me know if you have any further questions.

Text to Columns formatting issues with Date/Time

I am trying to figure out if this is an Excel bug or just a formatting issue. So I have a column with a date and time in the format m/d/yyy h:m AM/PM (ie. 10/21/2015 2:21:00 PM), and am trying to split it into two individual columns: one with the date and one with the time. I tried using fixed width first, but ended up using delimited just so I could split it exactly where I wanted.
For some reason when it splits the two up, the actual value for time changes. I will end up with one column with the date and a time of 12am (10/21/2015 12:00 AM) and one column with the initial time minus 12 hours (2:21:00 AM).... Trying to figure out why there is still a time value in the date column and why the time value changes. Ideally I want to have a column with 10/21/2015 and another with 2:21:00 PM.
I've tried changing the format of the initial date/time combination etc. and it keeps on subtracting 12 hours from the initial time when it splits.
Has anybody experienced or heard of similar issues?
I think your question is confusing, for example I tried using fixed width first, but ended up using delimited just so I could split it exactly where I wanted. seems back-to-front, but you have a datetime value for October 21, 2015 14:21 hrs, want that as a date in one column and 02:21:00 PM in the next and your environment is UK style (ie day before month).
IF so Text to Columns may be as confusing as helpful. Format the date column as date (to suit) and the time column as hh:mm:ss AM/PM (or similar) and the following formulae may suit, assuming your datetime value is in A1:
For date: =INT(A1)
For time: =MOD(A1,1)

Date is not converted exactly when read from excel

I have an Excel spreadsheet that is being read.
The value in the spreadsheet is 7/24/2014 10:43:33 AM
The cell value after being read using OpenXML is 41844.446908680555.
When I do this calculation to convert to a date:
dte = DateTime.FromOADate(double.Parse(value));
I get 7/24/2014 10:43:32 AM
Is this typical when converting date/time or am I missing something?
Thanks
It seems that DateTime.FromOADate(double.Parse(value)); is truncating rather than rounding the fractional seconds. Excel stores date/time as days and fractions of days since 1 Jan 1900 (with the intentional error of calling 1900 a leap year, supposedly for compatibility with Lotus 123 at the time).
Therefore, the number 41844.446908680555 translates to, given Excel's level of precision
7/24/2014 10:43:32.910
(actually: 7/24/2014 10:43:32.9099949030205)
Just format the cells as Dates. 41844.446908680555 is Excel's way of serializing the date value.
When Excel stores a date or time in stores it in a number format with the date January 1, 1900 = 1
so really when you’re storing a date with the date format you’re really just storing the numeric value of difference between the date and January 1, 1900
So for example 365 = jan-30-1900
And fractions of a number equal parts of the day so .5 = half a day or 12 hours.
And for the fun of it right now = 41885.75 or sept-3-2014 at 6PM or 41885.75 from jan 1 1900.
The reason why this is done is to now allowed dates to be used in mathematical functions. And it deals with a lot of problems that pop-up with dates such as leap year and also provides for easier ways to deal with time zones as well.

.NumberFormat sometimes returns the wrong value with dates and times

It seems that every week or so someone posts a question about dates being converted (corrupted?) to American format. Like many others, I have attempted to help but the problem is elusive. I now wonder if I have discovered the cause.
I am working on an application in which I need to extract data from an Excel worksheet and output it as strings formatted to match the value the Excel user can see. So if the value is “1” formatted to display as “1.00” then I want the string to be “1.00”.
I achieve this effect by testing the cell value to be a number, date or time. If it is, I retrieve the number format and use it to format the cell value so:
With .Cells(Row, Column)
Output string = Format(.Value, .NumberFormat)
End With
In most cases this gives me exactly the output I require. However, sometimes I get American dates and times when the source is formatted as a UK date or time.
After much experimentation with Excel 2003 and Excel 2007, I have discovered the cause. (I do not have access to Excel 2010 but from questions I deduce it has the same problem.) This question is in part intended to reveal this problem to the world because I can discover nothing on the internet to indicate that anyone else has noticed it. (No doubt someone will reply that they googled “xyz” and got the answer immediately.) However, the main purpose of this question is to seek suggestions for obtaining the result I need in all situations.
Typically I enter dates as, for example, “23mar12”. Excel recognises this as a date and formats it as “23-Mar-12”. I can select Format Cells and enter or select a custom format or select one of the date formats so I can have any format I can imagine wanting including non-English names for days and months.
However, in one case the format I select is not the format that is recorded: Custom format “dd/mm/yyyy” is recorded as Date format “* 14/03/2001”. This is not obviously a problem until further down the line.
I created a column of dates and times and formatted each with a different custom or standard format. I wrote a macro to extract the NumberFormat for each of these dates and times and write it as a string to an adjacent column. I also formatted the value using the number format and wrote that string to a third column.
In a number of cases the format selected and recorded by Excel was not the format returned by NumberFormat:
Excel format NumberFormat
Date: * 14/03/2001 m/d/yyyy
Date: * 14 March 2001 [$-F800]dddd, mmmm dd, yyyy
Date: 14/03/2001 dd/mm/yyyy;#
Date: 14/03/01 dd/mm/yy;#
Date: 14/3/01 d/m/yy;#
Date: 14.3.01 d.m.yy;#
Date: 2001-03-14 yyyy-mm-dd;#
Date: 14 March 2001 (1) [$-809]dd mmmm yyyy;#
Date: 14 March 2001 (2) [$-809]d mmmm yyyy;#
Custom: hh:mm:ss h:mm:ss
Time: * 13:30:55 [$-F400]h:mm:ss AM/PM
Time: 13:30:55 (1) hh:mm:ss;#
Time: 13:30:55 (2) h:mm:ss;#
Time: 01:30:55 PM [$-409]hh:mm:ss AM/PM;#
Time: 1:30:55 PM [$-409]h:mm:ss AM/PM;#
The values (1) and (2) in the Excel format column were added by me to indicate that there are two apparently identical formats. As can be seen from the NumberFormat column, in each case the second version suppresses a leading zero.
Most changes have no important effect. “[$-F800]” and so on are apparently dummy values with no effect. Apparently you can replace “F800” with an Microsoft country code to have the names of days and months translated to the language of that country.
However, the three standard formats that Microsoft marks with an asterisk are changed unacceptably. The dates are changed from little endian to middle endian; the time is changed from 24 hour to 12 hour and the day of the week has been added to “* 14 March 2001”.
The asterisk against the dates, references the comment: “Except for items that have an asterisk () in the Type list (Number tab, Format Cells dialog box), date formats that you apply do not switch date orders with the operating system.” The asterisk against the time, references the comment: “Except for items that have an asterisk () in the Type list (Number tab, Format Cells dialog box), time formats that you apply do not switch time orders with the operating system.”
If I have to, I can warn my users that standard date and time formats may not give the result desired. However, if they want the popular format “dd/mm/yyyy”, they cannot have it. “dd-mm-yyyy”, for example, is OK but custom format “dd/mm/yyyy” becomes date format “* 14/03/2001” becomes “m/d/yyyy”.
Returning to my opening point: is this strange handling of one particular date format the reason so many people claim their dates are sometimes being converted to American format and is this why the problem is so elusive? I have come across this type of problem elsewhere of one group of Microsoft programmers not knowing what another group are doing. Is this why some functions always work and other sometimes don’t? Some Microsoft programmers know where to look for the correct format and others don’t?
More importantly, for me, can anyone suggest:
How I obtain the true date or time format?
Some other way of determining the user’s chosen display format for a date or time?
BTW 1: I recall that thirty or so years ago I was told that the American military do not use month/day/year format; only American civilians use this format. Can anyone tell me if this is true?
BTW 2: The similar problem is with Excel colours. Excel holds its colours as "ggbbrr" while everybody else holds them as "rrggbb". The programmers for the .Net Excel inter-op were not told and and did not reverse the Excel colour number before using it to control the screen.
I have mainly come up against formatting and date issues when opening text files which have been saved with different regional settings. Two useful cell properties for dealing with this are:
.Text returns the cell value as it is displayed
.Value2 returns the unformatted cell value or date serial number.
As you say, standard date and number formats depend on windows regional settings and this may not be desired behavior as the same workbook can display differently in different regions. MS introduced the regional code prefixes in number formats (circa Excel 2000?) which enforce consistent display if needed but they need to be explicitly selected.
If you really want to see a date or number as the user entered it, you could extract the contents of the .xlsx file looking at the worksheet cell format and the shared strings xml definitions which list the number formats in the saved workbook. I don't really see a need to do this though as the underlying value is stored internally as a serial number and this will not change.
BTW 1: It's been almost 30 years since I was in the military...
I worked on helicopters and I was taught to use a format such as this in the aircraft logbooks: 3 Apr 12. So, that's how I still write dates. This way, there's no wondering about 4/3/2012 - is it April 3 or March 4?
I hacked this: I rewrite the original data in a known format. it relies on DateSerial and TimeSerial:
'Google spreadsheet stores dates in USA format (MM/DD/YYYY). We're in Australia, using DD/MM/YYYY, so we need to swap them.
'
With dc 'the cell who contains a date in USA format.
d = .Value 'capture value in USA format
t = TimeValue(d)
.NumberFormat = "dd/mm/yyyy" 'set to OZ format, so Excel knows the values were swapped in its internal math.
.Value = DateSerial(Year(d), Month(d), Day(d)) 'DateSerial takes y,d,m. We swap Month and Day components, to get OZ format dates
.Value = .Value + TimeSerial(Hour(t), Minute(t), Second(t))
dc.Font.Bold = True ' We bold the cells that are swapped, for debugging
End With
End If

Dynamic Date To Track The Maturity Date of Automatic Rollover Deposit

Suppose that I open an automatic rollover time deposit (ARO TD) account in a bank on January 17, 2017 (the value date). The funds in this account must be held for 3 months (the tenor). Since it's an ARO TD, the maturity date will be automatically renewed with no action required by me if I choose to do nothing. Today's date is July 18, 2017. So, my account will mature on October 17, 2017. If I open it on January 19, 2017, it will mature on July 19, 2017, and so on.
How do I track the maturity date of my account in Excel with only using inputs: deposit period and value date? Meaning, the maturity date will continually update to the next period each time it matures. I'm able to find the Excel formula for this:
=IF(EDATE(B2,A2*CEILING(DATEDIF(B2,TODAY(),"M")/A2,1))<TODAY(),EDATE(B2,A2*(1+CEILING(DATEDIF(B2,TODAY(),"M")/A2,1))),EDATE(B2,A2*CEILING(DATEDIF(B2,TODAY(),"M")/A2,1)))
The above formula works perfectly but it's too long. Could anyone here come up with a nicer and shorter formula than this?
You can use the DATEDIF function to do this. For reasons I don't understand, Excel doesn't suggest it when you're typing, but it exists and is documented.
DATEDIF is useful because you're interested in the number of months between dates. The earlier date of interest is the value date; the later date is today (actually yesterday, because as in your first example you want the date to tick on on the expiry date).
Once you have this number of months, you can get the exact number of tenors that is, add one, and then add that many months to the value date.
A formula is actually easier than the above text!
Your C2 cell should be:
=EDATE(B2, A2 * (FLOOR( DATEDIF(B2, TODAY()-1, "m") / A2, 1) + 1))
Working outwards from the middle, the DATEDIF gets the number of months from the value date to yesterday, we divide it by the tenor and floor to get the number of tenor periods that have passed, we add one to get the target number of tenor periods, we multiple by the tenor to get the number of months to add, then finally EDATE does the month-adding.
The result will be a date serial (eg 43025) so will need appropriate cell formatting.

Resources