davysouthernboy
asked on
Excel VBA Function To Convert Any Given Date to MySQL YYYY-MM-DD format?
Hi. I need a fuction that will take any given date value and convert that date value into MySQL's "YYYY-MM-DD" format.
I originally tried something like:
Range(CellRange).Select
Selection.NumberFormat = "yyyy-mm-dd"
NoteDate = Worksheet.Range(CellRange) .Value
But apparently, that just changes its appearance, not its value.
I originally tried something like:
Range(CellRange).Select
Selection.NumberFormat = "yyyy-mm-dd"
NoteDate = Worksheet.Range(CellRange)
But apparently, that just changes its appearance, not its value.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Should add - if you're using a UDF you should just use a standard cell function
=TEXT(datecell,"YYYY-MM-DD ")
=TEXT(datecell,"YYYY-MM-DD
If you want as a literal text string you will need to adjust accordingly - ie format cell as Text and then apply your Format, eg:
[code]
With Range(cellRange)
.NumberFormat = "@"
.Value = Format(.Value,"YYYY-MM-DD"
End With
[/code]