how do i change formate date from 25-Feb-2013 to Feb only?
Means here, it only extract the abbreviated month only.
i try to use this code but it does't work and it turn Feb to Jul
Sheet1.Range("A2:A9") = Format(Date, "mmm")
Sheet1.Range("A2:A9") = Application.text(Date, "mmm")
You may try:
Sheet1.Range("A2:A9").NumberFormatLocal = "mmm"
As suggested by #user3271518, this is found by recording a macro, changing the format and then looking at the macro recorded.
Related
So my problem is I have a Date that is defined as General in Excel as this "10 JUL 2021 10:30" I want to make it Excel Date.
kindly have a look at my picture for detailed understanding.
Need any kind of solution to automate this VBA or any formula,
Thanks in advance
If you need VBA to extract Date, please use the next function:
Function TextToDateX(txt As String) As Date
Dim arrD, arrM
arrM = Split("JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC", ",")
arrD = Split(txt, " ")
TextToDateX = DateSerial(CLng(arrD(2)), Application.match(arrD(1), arrM, 0), CLng(arrD(0))) + CVDate(arrD(3))
End Function
It can be tested as:
Sub testTextToDateX()
Dim txt As String, d As Date
txt = "10 JUL 2021 10:30"
d = TextToDateX(txt)
Debug.Print Format(d, "dd/mm/yyyy hh:mm")
End Sub
DateValue is localization related. Microsoft states: "DateValue recognizes the order for month, day, and year according to the Short Date format that you specified for your system". So, it may work or not.
In my case it doesn't...
I just tried using the DateValue() worksheet function, and every worked fine (normal Excel formula, no VBA needed):
=DATEVALUE("07 JUL 2021 10:30")
One thing that might be interesting for you: there exists a cell formatting (dd mmm yyyy hh:mm), which you seem to be using. (When you apply this on any cell, the value inside gets automatically formatted into that kind of date format.)
Edit, based on comment:
In case there's a comma in your date string, remove it first and then apply the DateValue() function:
=DATEVALUE(SUBSTITUTE("07 JUL 2021, 10:30",",",""))
I am using this below code
Range("A1") = Format$(Now, "dd/mm/yyyy h:mm:ss AM/PM")
and the o/p as shown in A1 is 02/12/2020 20:08:38 which is incorrect as today is 12th Feb 2020, so it should be 12/02/2020 20:08:38. Just the dd is interchanged with mm and there is no AM/PM. Already have checked the control panel--region and it's English (United Kingdom). OS is Win10. My system shows 12/02/2020 as the date. When I write 12/02/2020 manually it accepts as it is and doesn't change it.
Don't have any clue about it. Thanks for any help.
Instead of using Format$ (which returns a String anyway, not an actual datetime), change the NumberFormat of the cell:
Range("A1").NumberFormat = "dd/mm/yyyy h:mm:ss AM/PM"
Range("A1").Value = Now
I have a date: SAT 29 JUN 19. How do I convert it into date format e.g. 29 JUN 19 using Excel-VBA. Thanks.
By using this code:
wb.ActiveSheet.Cells(erow, 1) = CDate(Format(RemoveWkDay, "DD MMM YY"))
The output is: 29/06/2019
Based on your comments above, you can use:
wb.ActiveSheet.Range("A1:A30").NumberFormat = "dd mmm yy;#"
To do that for the whole column, use Range("A:A") instead.
In fact, you do not need VBA for this. You can just set that string as the custom format in the Sheet.
I have a column that has a name date: Friday, December 25, 2015
and I want to convert it to a date format: 12/25/2015 , that way I can perform other date functions.
I have unsuccessfully tried both changing the format directly and using the =DATEVAL() function.
Any direction would be great. thanks
First remove the day names
Ctrl+f and just replace "Friday," or "Saturday," or other days with ""
now your columns should be formatted like
"December 25, 2015"
Now use the dateval function like
=DATEVALUE("December 25, 2015")
Now select date from formatting and you should be good.
With text in A1 use:
=DATEVALUE(MID(A1,FIND(", ",A1,1)+2,9999))
and format as a Date:
I'm working with a date and time format from the Twitter API. It looks like this:
Tue Nov 26 20:44:15 +0000 2013
Is there a formula to convert this to a format that could be sorted chronologically? I don't need the +0000. Also not concerned about the day of week.
=DATEVALUE(MID(A1,9,3) & MID(A1,4,5) & RIGHT(A1,4)) + TIMEVALUE(MID(A1,11,9))
Then format as you like. As requested you would want a Custom Format of mmm dd HH:mm yyyy
Try this, assuming that your string is in A1:
=DATETIME(MID(A1, 5, 16) & MID(A1, 27, 4))
The two MID formulas cut out the parts of the string you want, namely the month, day, time, and year, but exclude the day of the week and the timezone. This produces a string that the DATETIME function can automatically recognize and covert into a native Excel date format.