"Year" and "Weeknum" Function in excel 2013 - excel

I have a problem with the "Year" and "Weeknum" functions in excel 2013.
I tried the formula below using the functions:
=YEAR(RC[1])&"_WW_"&IF(Weeknum(RC[1])<10,"0"&Weeknum(RC[1]),WeekNum(RC[1]))
On some dates, I get back "#VALUE!" and
And the correct field for other dates...
for example:
for the date "11/30/2013 20:15:00", I'm getting "#VALUE"
for the date "12/07/2013 20:15:00", I'm getting "2013_WW_28"
when evaluating formula, both "Year" and "weeknum" return "#VALUE!".
and On both of the examples, the date field is set as "General" (trying playing with it and change it to "long date" or "short date"' and it didn't work...)

If the format is general in this context that means your "dates" are text values
The only dates that are deemed valid are those where day <= 12......and those are being interpreted the wrong way round hence wrong WEEKNUM.
You can try changing to valid dates with "text to columns" but you may lose the times, is that a problem?
Select date column then.....
Use Data > Text to Columns > "Fixed width" > Next > at step 2 insert a line between times and dates > Next > at step 3, with date column selected, under "column data format" choose "date" and the source format (MDY) > OK
This should convert to valid date format for your region and formula should work as expected

Related

Convert date format DD/MM/YYYY to DD/MM/YY using Excel-formula

I need to convert the date format DD/MM/YYYY to DD/MM/YY using formulas in Excel. The key thing is that it can't be in "text" format after the formula is done.
I have tried with
= IF( CELL("type", $A2) = "v", $A2, VALUE(DAY(DATEVALUE($A2))&"/"&MONTH(DATEVALUE($A2))&"/"&YEAR(DATEVALUE($A2))-2000))
where cell A2 has the text "15/11/2019". My goal is to convert it into 15/10/19 (Excel DATEVALUE and VALUE functions keeps converting 19 into 2019).
Any help is much appreciated.
An actual date in Excel (not text that looks like a date) is stored as a number.
It is the number of days since 1/1/1900.
What you see is just this number formatted in a user readable way.
To change this custom formatting from DD/MM/YYYY to DD/MM/YY, got to the formatting menu on the "Home" tab:
And select "More Number Formats". Then select "Custom", and enter "dd/mm/yy" in the "Type:" field and click OK:

day and month are reversed

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)

excel 2013 convert column data format from 'yyyymmdd hhmm' to yyyy-mm-dd

How can i convert in excel 2013 column data format from 'yyyymmdd hhmm' to yyyy-mm-dd
Click on any cell in the column and run this macro:
Sub DateFormat()
With ActiveCell.EntireColumn.Cells
.NumberFormat = "yyyy-mm-dd"
End With
End Sub
Firstly, click on the top of the column to select all of the cells within that column, then right click on a random cell within that column and click 'Format Cells', from here a box will show up.
The box will have all different format rules, and by default it should be on the 'Number' tab within the box, from here select 'Date' and then you will be able to select the appropriate type of date format from here that you wish to have.
For your case you should see one corresponding to your yyyy-mm--dd format
If it is text-to-text: =LEFT(A1,4)&"-"&MID(A1,5,2)&"-"&MID(A1,7,2) (split and rejoin the string)
If it is date-to-text: =TEXT(A1,"yyyy-mm-dd")
If it is text-to-date, make a date with: =DATE(LEFT(A1,4),MID(A1,5,2),MID(A1,7,2)) (split the string and give the parts to the DATE function) ...
... to show date type cells in a different format, use methods above (if you don't have yyyy-mm-dd in your "Date" options, you can type it in under "Custom")

Convert text (12.05.79) to date in excel

I have imported some dates into an excel document and I need to format them as dates not text strings.
The format is like this: 12.05.79 but when I set the format to date excel doesn't do anything.
Any way to do this?
C
Two possible ways to convert "in situ" without an extra column
1 - use "Text to columns"
Select column of dates then Data > text to columns > Next > Next > "under column data format" select "Date" and the format from dropdown (MDY or DMY) > OK
2 - use Edit/Replace. Replace "." with "/" (in both cases without quotes)
Changing the format doesn't change the value (or in this case text). You'll have to use a macro, or just use a helper column with the following formula. You can then copy / paste values and remove the first column
=DATEVALUE(SUBSTITUTE(A1,".","/"))

Excel Date Conversion from yyyymmdd to mm/dd/yyyy

I have been searching for about an hour on how to do this in Excel.
I have an Excel file that was created from an old system and I am pulling information from a SQL Server Database, I will be inputting the information back into the SQL Server Database and would like the Dates to match.
I have tried Creating a Custom Format, but I am unsure if I even did it Correctly. I found several places where they want to go the other way mm/dd/yyyy to yyyymmdd but they have not been helpful.
I am unfamiliar with using VBA in any Microsoft Products otherwise I am sure that this would be a simple Task.
I have two separate columns that need to be changed.
How do I Format the entire column from (float)yyyymmdd to a (Date)mm/dd/yyyy
You can convert the value to a date using a formula like this, next to the cell:
=DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2))
Where A1 is the field you need to convert.
Alternatively, you could use this code in VBA:
Sub ConvertYYYYMMDDToDate()
Dim c As Range
For Each c In Selection.Cells
c.Value = DateSerial(Left(c.Value, 4), Mid(c.Value, 5, 2), Right(c.Value, 2))
'Following line added only to enforce the format.
c.NumberFormat = "mm/dd/yyyy"
Next
End Sub
Just highlight any cells you want fixed and run the code.
Note as RJohnson mentioned in the comments, this code will error if one of your selected cells is empty. You can add a condition on c.value to skip the update if it is blank.
Do you have ROWS of data (horizontal) as you stated or COLUMNS (vertical)?
If it's the latter you can use "Text to columns" functionality to convert a whole column "in situ" - to do that:
Select column > Data > Text to columns > Next > Next > Choose "Date" under "column data format" and "YMD" from dropdown > Finish
....otherwise you can convert with a formula by using
=TEXT(A1,"0000-00-00")+0
and format in required date format
Here is a bare bones version:
Let's say that you have a date in Cell A1 in the format you described. For example: 19760210.
Then this formula will give you the date you want:
=DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2)).
On my system (Excel 2010) it works with strings or floats.
for converting dd/mm/yyyy to mm/dd/yyyy
=DATE(RIGHT(a1,4),MID(a1,4,2),LEFT(a1,2))
Found another (manual) answer which worked well for me
Select the column.
Choose Data tab
Text to Columns - opens new box
(choose Delimited), Next
(uncheck all boxes, use "none" for text qualifier), Next
use the ymd option from the Date dropdown.
Click Finish

Resources