Within an Excel cell, I want to have the current (dynamic) date time printed.
I tried with following format:
TEXT(TODAY(); "ddmm");TEXT(TIME(HOUR(NOW());MINUTE(NOW());SECOND(NOW()));"mmss")
The format cell is not formatted as text. However, when I select the cell I have exactly that what is typed iso 07111533
I tried already with TEXT(TODAY(); "ddmm") and then my cell is filled with 0711, which is ok.
Expected result should be something like 07113815
Actual result:
TEXT(TODAY(); "ddmm");TEXT(TIME(HOUR(NOW());MINUTE(NOW());SECOND(NOW()));"mmss")
You're over-complicating:
=TEXT(NOW(),"ddmm") & TEXT(NOW(),"mmss")
Related
I have an Excel sheet with a formatted cell as text with a timestamp from I need to extract the date in format dd/mm/yyyy and store the result in a cell as date. What I normally do on other calculations is get the result for first line, populate to bottom line, then copy and paste as values, not the formula itself. The file could have 30000 lines.
I have tried with the date function which works fine on the sheet, but not on the VBA code.
Any help are welcome
The Excel sheet look as the image
Excel will automatically recognize most dates. By only supplying the first 10 characters of the string, i.e. the date, Excel will know what to do with it.
Your formula could be simplified, into a cell with a dd/mm/yyyy format:
=DATEVALUE(LEFT(A1,10))
The corresponding VBA function would look like:
Format(Left(Range("A1").Value, 10), "dd/mm/yyyy")
So I have this data directly copy/paste from iTunes :
Excel have "XX:XX:00" format which is "hh:mm:ss" but as you can imagine, it is more like "mm:ss:00". Musics are not hours long !
As it's not a direct cell format problem, I couldn't find easily the answer on internet. I need sometihng to put the 2 "00" at the start (in order to have "00:mm:ss")
EDIT : It was a cell format comprehension problem.
You can just divide the cell value to 60 like so
and then choose custom format for that cell like this
Format the cell with the time (C1) as "General". If it retains its value, like 11:42, then convert it with =TimeValue(C1) and format the cell as Custom mm:ss
If it changes to something like 0.4875 then convert it with =C1/60 and format the result as Custom mm:ss
This formula should work:
="00:" & MID(TEXT(A1,"h:mm:ss"),SEARCH(":",TEXT(A1,"h:mm:ss"))+1,3) & RIGHT(TEXT(A1,"h:mm:ss"),2)
The important element is to convert the time into a text string.
Change A1 to the first cell of Duration (Duree) & copy the formula downward
Then, you can copy the result and paste it as values
Edit: you can also use just the right function:
="00:"&RIGHT(TEXT(A1,"h:mm:ss"),LEN(TEXT(A1,"h:mm:ss"))-SEARCH(":",TEXT(A1,"h:mm:ss")))
I have a column in Excel Sheet which contains all the dates in custom dd-mm-yyyy format. I need to convert all these dates to text without losing the format. If I am changing the cell format to Text, I am losing the format. I tried to copy the cell values as values but did not work. I searched a lot on the internet, but did not find any useful resource. What's the possible solution?
Try using the TEXT function.
=TEXT(A1,"dd-mm-yyyy")
Use this formula for keeping the long date format from "A1" cell in another cell (exp: "B1"):
=TEXT(A1,"[$-F800]dddd, mmmm dd, yyyy")
The cell "A1" is a cell contains a date (such as today date with «today()» formula) with long date format.
Also, you can use this VBA code for getting same format with specify font and size in print's header:
ActiveSheet.PageSetup.RightHeader = "&""Arial Rounded MT Bold,Regular""&16" & Range("B1").Value
This code will shows the "B1" cell (as a text from "A1" cell) in Right of Header in Print.
I have a cell with the following content:
01/02/2015
The cell is date formatted.
Then I copy the value and put it in my module class:
Set Line = New CTravelLine
Line.Date= Cells(1, 8).value
Everything works fine until the moment I put this value in another cell:
The value 01/02/2015 becomes 02/01/2015.
I am using this format (dd/mm/yyyy). I have the impression that when the days are numerically lower than the month, the 2 values are reversed. The values are reversed whatever the method I tried:
Method 1:
Dim WrdArray() As String, datetest As String
WrdArray() = Split(travelLine.Date, "/")
datetest= WrdArray(0) & "/" & WrdArray(1) & "/" & WrdArray(2)
Cells(5, 5) = datetest
Method 2:
Cells(5, 5) = travelLine.Date
I don't understand how I can solve this problem.
This might have happened due to 'Regional formatting problem'.
Excel has a habit of forcing the American date format (mm/dd/yyyy) when the dates have been imported from another data source. So, if the day in your date happens to be 1 - 12, then Excel will switch the date to mm/dd/yyyy.
When dates are imported from a text file, there is an option in the VBA code to apply regional format which corrects this problem.
OR
Change number format of date column in excelsheet from 'date' format category to 'text'; save it.
(After Saving run the VBA Code if you have any. Now check whether the date format is 'text' or changed back to 'date'.)
If it has changed back to 'date' try to fix it as 'text'
If it's 'text'; Correct the erroneous date cells and save the excel sheet. This will make dates not to change automatically to American Format.
Long story short, I had a similar problem where the dates are working just fine in some cells but keep flipping in others regardless if I copy paste or enter manually, I did the whole data text to column and cell formatting solutions and all of that didn't work.
The solution actually is not in excel, it's in the region and language setting.
To have the dates display as MM/DD/YYYY in the formats tab change the format to US.
To have the dates display as DD/MM/YYYY in the formats tab change the format to UK.
I had the same issue as you .
Let me explain what I want to do :
I have a csv file with some date.
I copy a range of my sheet in variable table. The range contain some columns with dates.
I make some manipulations on my table (very basic ones)
I transpose my variable table (since only the last dimension of a variable table can be increase)
I put my variable table on a new sheet.
What I found:
There is no date issue after executing step 1-4. The date issue shows up when writing on the sheet...
Considering what Avidan said on the post of Feb 24 '15 at 13:36, I guess it is excel which forces the American format mm/dd/yyyy... So I just change the date format at the very beginning of my program :
Before starting any manipulation date:
do
.Cells("where my date is") = Format(.Cells("where my date is"), "mm dd yy")
execute your program
write the table on a sheet
back up to the date format you like directly on the sheet
Just use:
Line.Date = cDate(Cells(1, 8).value2)
I have two cells in Excel. one has a string and the other one has a date. in the third cell I want to put the date and the string together. For example:
A1 = "This "
A2 = "03/03/1982"
I want A3 to be:
This 03/03/1982
when I try to put this in the A3 formula: = A1 & A2 it returns some funny numerical value for the date and does not give me the literal date.
Don't know if it's the best way but I'd do this:
=A1 & TEXT(A2,"mm/dd/yyyy")
That should format your date into your desired string.
Edit: That funny number you saw is the number of days between December 31st 1899 and your date. That's how Excel stores dates.
This is the numerical representation of the date. The thing you get when referring to dates from formulas like that.
You'll have to do:
= A1 & TEXT(A2, "mm/dd/yyyy")
The biggest problem here is that the format specifier is locale-dependent. It will not work/produce not what expected if the file is opened with a differently localized Excel.
Now, you could have a user-defined function:
public function AsDisplayed(byval c as range) as string
AsDisplayed = c.Text
end function
and then
= A1 & AsDisplayed(A2)
But then there's a bug (feature?) in Excel because of which the .Text property is suddenly not available during certain stages of the computation cycle, and your formulas display #VALUE instead of what they should.
That is, it's bad either way.
Another approach
=CONCATENATE("Age as of ", TEXT(TODAY(),"dd-mmm-yyyy"))
This will return
Age as of 06-Aug-2013
Thanks for the solution !
It works, but in a french Excel environment, you should apply something like
TEXTE(F2;"jj/mm/aaaa")
to get the date preserved as it is displayed in F2 cell, after concatenation.
Best Regards
You can do it this simple way :
A1 = Mahi
A2 = NULL(blank)
Select A2 Right click on cell --> Format cells --> change to TEXT
Then put the date in A2 (A2 =31/07/1990)
Then concatenate it will work. No need of any formulae.
=CONCATENATE(A1,A2)
mahi31/07/1990
(This works on the empty cells ie.,Before entering the DATE value to cell you need to make it as TEXT).
I found that for this situation, the simplest solution is to define a Custom number format for the cell containing the date. The format in this case should be:
"This:" mm/dd/yyyy
To set this format:
Right click on the cell
Select Format Cell
Select Number tab (should be displayed by default)
Pick Custom from the Category list
Specify the format in the "Type" field
Press OK
Note: If you really want the preceding text to be picked from a cell, this solution will not work as described.