=text(5/7/19,[Windows date format]) depends on the computer you are opening the Excel file from. For instance: =text(5/7/19, "mm/dd/yy") works on the company computer because that's how the windows formatted the date, but in my computer, it has to be =text(5/7/19, "dd/mm/yy") else it will return a different value and using other functions such as =datevalue(text(5/7/19, "mm/dd/yy") will return a #VALUE! error on my home computer. This is not good because it is very variable when the file is being moved around computers. How to standardize this?
So what about:
=TEXT(43592,"mm")&"/"&TEXT(43592,"dd")&"/"&TEXT(43592,"yy")
Or reference a cell where you have put your date.
Unfortunately I don't think it is possible - see the this link
Quote:
Problem: The value in the date_text argument is not in sync with the system’s date and time settings*
If your system date and time settings follow the mm/dd/yyyy format,
then a formula such as =DATEVALUE(“22/6/2000”) will result in a #VALUE! error. But the same formula will display the correct value when the system's date and time is set to dd/mm/yyyy format.
Solution: Make sure that your system’s date and time settings (both Short time and Long time) matches the date format in the
date_text argument.
I think the only solution is to make sure that your date is in the valid (i.e. recognised by the system) date format before any other function (like DATEVALUE) is applied.
It will be easy to achieve if your function is simply =text(5/7/19,[Windows date format]). You can reference your cell field (e.g. =[#Date]) and format a given cell using an "universal" date format (the ones that start with * sign).
However, if you are combining =text(5/7/19,[Windows date format]) with some other formula (e.g. when you want to display a full sentence like A very important event happened on 5/7/19) then, unfortunately, cell format won't save you here and we're out of solutions. In such case the end user would need to manually modify the date cell in order to make it recognisable.
Related
Could someone please tell me what cell format I should use to format the following so that they are recognised in a date time format I can then use to sort from oldest date to newest date please?
02-DEC-21 21.32.01.666000000
02-DEC-21 22.16.50.588000000
03-DEC-21 00.31.06.414000000
03-DEC-21 03.50.11.644000000
03-OCT-21 18.04.41.267000000
04-DEC-21 05.39.27.832000000
I’ve tried using dd-mmm-yy hh.mm.ss.000 (can’t enter more than three 0’s in milliseconds) and also without the .000 at the end but the cells don’t get recognised as dates when I try and sort them
Thanks
You can use two formulas to retrieve the date part and the time part.
I named the range with the dates DateColumn
To retrieve the date part: =DATEVALUE(SUBSTITUTE(LEFT(DateColumn,9),".",":"))
To retrieve the time part: =TIMEVALUE(SUBSTITUTE(MID(DateColumn,11,8),".",":"))
To retrieve the whole date incl. time:
=DATEVALUE(SUBSTITUTE(LEFT(DateColumn,9),".",":")) + TIMEVALUE(SUBSTITUTE(MID(DateColumn,11,8),".",":"))
These formulas return a number, e.g. 44532 for 02-DEC-21 or 0,92835648 for 22.16.50 or 44532,92835648 for the whole date with time. You have to format them accordingly.
But be aware: this will only work on an english system.
E.g. on a German system only Dez or Okt would get recognized.
I have a userform and I take start and end dates from user as in dd.mm.yyyy format. To make it easier to compare dates, I want to turn it to a double or long type of value. I have tried as in below but it gives me an error of type mismatch.
endDate is already defined as Double and as you can see, Me.g_end.Value is string in proper format. Why do I get this error, and how can I handle it?
Also I need to add, DateValue(Me.g_end.Value) works fine with my friend to get value of date who uses Excel 2013. I use Excel 2016.
You need to enter dates in a valid format in order for Excel to recognize them as dates.
As far as I know, nowhere uses dots (periods) in dates. (As I recall, nowadays only one country in the world even recognizes dots as am official date separator.)
Click your Start menu and type Region to find and open Windows Region and Language Settings.
Note the format that your system is expecting for Short Date, including the symbol between each date part, and try entering your dates in Excel like that.
I am currently trying to convert yyyymmdd type of date to a ddmmyyy format.
I've tried using DATE function and something like this:
=DATE(LEFT(A3;4);MID(A3;5;3);RIGHT(A3;7))
Original date for this function is 20120401 but the formula returns: 16.12.2104.
I've tried using functions YEAR, MONTH and DAY instead of LEFT, MID and RIGHT but that's not the right way.
I also tried using DATEVALUE but since Excel probably doesn't recognize yyyymmdd as a date, it gives me a #VALUE! error.
I've found a couple of solutions for SQL but it isn't my strong side yet - and this should be achievable easily in Excel.
Is there a way to do this in Excel?
Applying =DATE(LEFT(A3;4);MID(A3;5;3);RIGHT(A3;7)) to 20120401 in A3 is effectively to reassemble the component characters as below on the left:
These effectively become converted as on the right.
The solution was simply to exclude the digits highlighted red with:
=DATE(LEFT(A3;4);MID(A3;5;2);RIGHT(A3;2))
but the locale might have been a factor and when dealing with date serial numbers and/or what appears to be a date but is a string various other issues might have been involved.
Consider:
=DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2))
I have a spreadsheet I created mid-August which has a table with one column for every day since then. The column header is the day's date. The date is displayed how I want it to be displayed: "dd/mm/yyyy"
However, I have macro which needs to read these dates in order to perform its work. Because I am using a table, the dates seem to be held as text rather than as 5-digit numbers (when I set the header cells' format to "General", it remains with the "dd/mm/yyyy" format rather than changing to a 5-digit number. This wasn't a problem until the 1st of September, after which CDate (in the macro) began reading these dates as "mm/dd/yyyy"
Is there any way to make CDate recognise the Australian date format rather than the American? Or failing that, make the table headers stay as dates rather than as text? I'd rather avoid having to convert the Table back to a range, as the macro is designed to use table attributes, ListColumns etc.
UPDATE:
I've narrowed down the problem. It isn't the date, but the ListColumn.Name property. For some reason it is re-converting my date. I'm using Format() to set the date format, like so:
CreateHistoryColumn.Name = Format(headerDate, "dd/mm/yyyy")
MsgBox Day(headerDate) & "/" & Month(headerDate) & "/" & Year(headerDate)
MsgBox Format(headerDate, "dd/mm/yyyy")
MsgBox CreateHistoryColumn.Name
Where CreateHistoryCol is an object of class ListColumn. The 3 MsgBox calls display the following:
6/9/2012
06/09/2012
9/06/2012
So the Format() call formats the date correctly, but the call to ListColumn.Name serves to alter the format to "mm/dd/yyyy".
From help file:
CDate recognizes date formats according to the locale setting of your system. The correct order of day, month, and year may not be determined if it is provided in a format other than one of the recognized date settings.
I hate relying on the locale because most of the time it seems to do the opposite of what I intended, plus it makes code less portable.
I usually deal with dates as explicitly as possible:
Split your string into the various parts (year, month, day, as well as hour, minute, second if relevant)
Stick the various parts in the DateSerial function. This returns a Date type. (To that you can add the output of TimeSerial, if applicable.)
If necessary for display purposes, format this Date as appropriate using the Format function, which returns a string.
Here's a worked example.
As I showed in the update, the ListColumn.Name method was responsible for the unwanted conversion. I still don't know why, but there is any easy fix:
CreateHistoryColumn.Name = CLng(headerDate)
This forces the header to be treated as a number, and therefore it can be recognised as its proper date. I can't explain it any further than that.
I have a program that gets input in the form of an excel which it reads by querying (select * into a dataset).
The excel is created by the customer.
The excel contains a date column.
The problem is, that when looking into the dataset, the date column format is sometimes like mm/dd/yyyy and sometimes dd/mm/yyyy. (1/25/1970) (25/1/1970)
I guess it depends on the locale on the machine which the excel was made.
How can my program know what is the date format in the excel?
Not sure whether your question is about output or input...
For output:
You did not mention the database type. But the rule is: make your dates the american way: mm/dd/yyyy. For Jet, I generally use Format(MyDate, ""\#dd\/mm\/yyyy\#"")
("\" is the escape character, it makes sure the next character is output "as is")
For input:
Try reading the cell format ? range("a1").NumberFormat
However on my PC, with French setup a date displayed as 15/2/2011 has a returned format = m/d/yyyy so little use here !