How to concatenate string with DATE()? [duplicate] - excel

This question already has answers here:
Excel Date to String conversion
(10 answers)
Closed 5 years ago.
In Excel, I'm trying to have a cell look something like:
by no later than August 27, 2012
When I try to concatenate a string with a DATE, for example:
="by no later than " & DATE(YEAR(TODAY()),MONTH(TODAY()),DAY(TODAY()))
I get an output like this:
by no later than 41118
How can I get a date to show up instead of an integer?

DATE builds a date timestamp. You need to convert that to a string. See this question for how to do so:
Excel Date to String conversion
It would look something like this:
=TEXT(DATE(YEAR(TODAY()),MONTH(TODAY()),DAY(TODAY())), "DD/MM/YYYY hh:mm:ss")

You don't really need DATE function at all for today's date, you could use just
="by no later than "&TEXT(TODAY(),"mmmm d, yyyy")

If you format the cell containing your number (41118) as Date, you'll get exactly 27.8.2012. Simple!

Related

Is formula can extract long space date from text string?

i have do the research all over the internet but most of the references is about dd/mm/yy or dd.mm.yy but i want something like dd mmmm yyyy (between are using space)
and i have tried to used
=MID(A1,SEARCH("?? ????? ????",A1),13)
to extract the date from the text string but it will error in some cell such as display the text not date.
my date will be in 2 type below:
on (1 April 2020)
on 1 April 2020
if on has CONCAT and FILTERXML:
=CONCAT(IFERROR(FILTERXML("<a><b>"&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,")",""),"(","")," ","</b><b>")&"</b></a>","//b[starts-with(following::*[1],"&{"'Jan'","'Feb'","'Mar'","'Apr'","'May'","'Jun'","'Jul'","'Aug'","'Sep'","'Oct'","'Nov'","'Dec'"}&")]"),""))&" "&CONCAT(IFERROR(FILTERXML("<a><b>"&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,")",""),"(","")," ","</b><b>")&"</b></a>","//b[starts-with(.,"&{"'Jan'","'Feb'","'Mar'","'Apr'","'May'","'Jun'","'Jul'","'Aug'","'Sep'","'Oct'","'Nov'","'Dec'"}&")]"),""))&" "&CONCAT(IFERROR(FILTERXML("<a><b>"&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,")",""),"(","")," ","</b><b>")&"</b></a>","//b[starts-with(preceding::*[1],"&{"'Jan'","'Feb'","'Mar'","'Apr'","'May'","'Jun'","'Jul'","'Aug'","'Sep'","'Oct'","'Nov'","'Dec'"}&")]"),""))
Note: this returns the string. If one wants a true date then:
=--(CONCAT(IFERROR(FILTERXML("<a><b>"&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,")",""),"(","")," ","</b><b>")&"</b></a>","//b[starts-with(following::*[1],"&{"'Jan'","'Feb'","'Mar'","'Apr'","'May'","'Jun'","'Jul'","'Aug'","'Sep'","'Oct'","'Nov'","'Dec'"}&")]"),""))&" "&CONCAT(IFERROR(FILTERXML("<a><b>"&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,")",""),"(","")," ","</b><b>")&"</b></a>","//b[starts-with(.,"&{"'Jan'","'Feb'","'Mar'","'Apr'","'May'","'Jun'","'Jul'","'Aug'","'Sep'","'Oct'","'Nov'","'Dec'"}&")]"),""))&" "&CONCAT(IFERROR(FILTERXML("<a><b>"&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,")",""),"(","")," ","</b><b>")&"</b></a>","//b[starts-with(preceding::*[1],"&{"'Jan'","'Feb'","'Mar'","'Apr'","'May'","'Jun'","'Jul'","'Aug'","'Sep'","'Oct'","'Nov'","'Dec'"}&")]"),"")))
And format the date as desired.

Changing format of TODAY() in excel

I'm using today to aquire todays date and then adding a static value to the end of it using the following:
=TODAY()&"T23:00:00"
Which Returns 43202T23:00:00
I really need it in the format 2018-04-12T23:00:00
Any help on this would be great!
There are a couple ways to accomplish this, depending on whether your goal is a formatted String (to display) or a numeric value (such as data type Date) for storing or using with calculations.
If you want a formatted date/time result (to display to the user)...
Use the TEXT worksheet function:
=TEXT(TODAY(),"yyyy-mm-dd")&"T23:00:00"
...the reason this works is because TODAY() returns a Date data type, which is basically just a number representing the date/time, (where 1 = midnight on January 1, 1900, 2 = midnight on January 2, 1900, 2.5 = noon on January 2, 1900,etc).
You can convert the date type to a String (text) with the TEXT function, in whatever format you like. The example above will display today's date as 2018-04-12.
If, for example, you wanted the date portion of the string displayed asApril 12, 2018 then you would instead use:
TEXT(TODAY(),"mmmm d, yyyy")
Note that the TEXT worksheet function (and VBA's Format function) always return Strings, ready to be concatenated with the rest of the String that you're trying to add ("T23:00:00").
If you want to use the result in calculations...
If you instead want the result to be in a Date type, then instead of concatenating a string (produced by the TEXT function) to a string (from "T23:00:00"), you could instead add a date to a date:
=TODAY()+TIME(23,0,0)
or
=TODAY()+TIMEVALUE("23:00")
..and then you can format it as you like to show or hide Y/M/D/H/M/S as necessary with Number Formats (shortcut: Ctrl+1).
More Information:
MSDN : TEXT Function (Excel)
MSDN : TIMEVALUE Function (Excel)
MSDN : TIME Function (Excel)

How to a convert a string in this format "20180101" into a date value like 01/01/2018 in Excel? [duplicate]

This question already has answers here:
Changing YYYYMMDD to MM/DD/YYYY
(5 answers)
Closed 4 years ago.
What formula can I use to transform the string into a date value that will appear as 01/01/2018?
If you are trying to do this from a formula into another cell, and not in situ (For which, use "Text to Columns" as per Jeeped's answer), you can either combine DATE and MID, or use REPLACE and convert with +0 or DATEVALUE:
=DATE(MID(A1,1,4), MID(A1,5,2), MID(A1,7,2))
OR
=REPLACE(REPLACE(A1,7,0,"-"),5,0,"-")+0
OR
=DATEVALUE(REPLACE(REPLACE(A1,7,0,"-"),5,0,"-"))
(Where A1 is the date to convert)
The first formula just cuts the number up into 2018 01 01 and uses those as Year, Month and Day. The second 2 work by first Inserting (i.e. REPLACE 0 characters) a hyphen at position 7 ("201801-01") and then at position 5 ("2018-01-01") and converting the string back to a number/date.
Use Data, TextToColumns, Fixed width, Date: YMD, Finish. Possibly Date: YDM depending on your string date format (you provided an ambiguous example).
use the code below
=RIGHT((text),2)&"/"&MID((text),5,2)&"/"&LEFT((text),4)
Use the DATEVALUE() function which takes as input a text format. Not that if your output cell is not in Date format you will see a simple int insteade of the expected 1/1/2016.
I refer you to the DATEVALUE function documentation for more insight on the input format and so on

Cannot convert string to date in R [duplicate]

This question already has answers here:
What are the "standard unambiguous date" formats for string-to-date conversion in R?
(8 answers)
Closed 9 years ago.
I need your help to figure out the following problem-
I am trying to convert a date column from string to actual date format. I have tried using as.Date
However, it is showing an error message:
Error in charToDate(x) :
character string is not in a standard unambiguous format
the date column I have in csv file is like this:
Date
03/17/2003
05/31/2003
09/06/2003
10/18/2003
07/15/2003
09/19/2003
The problem is some of the dates are in string and some are in actual date format. I have tried to format it from excel - didn't work
Tried to copy and paste it to notepad and then import it again - didn't work either.
You need to learn about the help system in R. One brief look at help(as.Date) may have told you about the format argument:
R> dt <- c("03/17/2003", "05/31/2003", "09/06/2003")
R> as.Date(dt, "%m/%d/%Y")
[1] "2003-03-17" "2003-05-31" "2003-09-06"
R>
Edit: These days we also have a helper package that does the format-finding for you:
> dt <- c("03/17/2003", "05/31/2003", "09/06/2003")
> anytime::anydate(dt)
[1] "2003-03-17" "2003-05-31" "2003-09-06"
>
This works for datetimes (using anytime()) and dates.

CSV date and separator issue

I have a CSV file, delimited by comma and I have some date values inside it, like "01/13/2010 05:00:00 AM", or "04/01/2010 05:00:00 AM". The issue is that when I open the CSV file with Microsoft Excel, it will show these days as 01/13/2010 05:00:00 AM and 04/01/2010 05:00, respectively. The value of the second one is 04/01/2010 05:00:00, but it still shows 04/01/2010 05:00. I've made a few tests and I've realized that Excel is not able to determine which is the day and which is the month in a few cases. In fact Excel gets a string like:
__/__/____ __:__:__ __
It deduces from the last two characters (AM/PM) the value of hour, it knows what the minute and second is, also, it determines the year when it sees the four-character long number sequence, so the question is about month and day. If the first and the second number from the string are both <= 12, then it can't determine which is the month and which is the year, so it messes up my date format.
I would like to have a date format such as
MM/dd/yyyy HH:mm:ss AM/PM
and I've found out that using the function called TEXT is able to do just that, like this:
=TEXT("04/13/2010 05:54:00 AM", "MM/dd/yyyy HH:mm:ss AM/PM")
It works like a charm, but it still guesses which is the day and which is the month. However, assuming that the clients will have the same default date format as the data in the CSV, the month and the day won't be inverted. However, I don't want to open Excel and type the formula in, because I need to give this file to clients and it should show the right value whenever they open the file. So, I need to write the formula inside the comma-separated file, but... TEXT is two-dimensional and there is a comma separating my date from my format.
If I type:
= ABS(-5),=TEXT("04/13/2010 05:54:00 AM", "MM/dd/yyyy HH:mm:ss AM/PM")
into my file, I will see 3 cells, the first being 5, the second is =TEXT("04/13/2010 05:54:00 AM" and the third is "MM/dd/yyyy HH:mm:ss AM/PM").
How can I prevent this behavior? Can I use something else instead of the comma inside my function call? Or can I change the separator? Or is there a better solution?
Can you enlighten me, to learn how can I enter function calls inside a CSV file?
Thanks in advance to everybody who tries to help,
Lajos Árpád.
If I type:
= ABS(-5),=TEXT("04/13/2010 05:54:00 AM", "MM/dd/yyyy HH:mm:ss AM/PM")
into my file, I will see 3 cells, the first being 5, the second is
=TEXT("04/13/2010 05:54:00 AM" and the third is "MM/dd/yyyy HH:mm:ss AM/PM").
To make this example work, you need to surround your second data item with double-quotes to escape the comma. As a consequence, you need to use double double-quotes to have them interpreted as double-quotes inside the double-quotes -- I hope this is a readable sentence.
So the example you give should work if you use this in your file:
=ABS(-5),"=TEXT(""04/13/2010 05:54:00 AM"", ""MM/dd/yyyy HH:mm:ss AM/PM"")"

Resources