Best way to convert date from source data field and hardcode date
I have a date from source file in format of 30-Sep-2016 I need to convert this to GP date format and hardocde in 15 for the day so it woud read 09/15/2016. What’s the best way to handle this conversion plus hardcode of day?
Answers
While we have a couple options to take that date string and then re-format it, since we want to change the day, then our only choice is to format it ourselves.
Best approach there is using the substring() function and then parse out the month and year. Then add in the “15” for the day and the “/” and you got it.
Dim newDate As String = “”
Dim sDate As String = “30-Sep-2016”
Dim sMonthInWords As String
Dim sYear As String
Dim sMonth As String = “”
Dim sDay As String = “15”
sMonthInWords = sDate.Substring(3, 3)
sYear = sDate.Substring(7, 4)
Select Case sMonthInWords
Case “Jan”
sMonth = “01”
Case “Feb”
sMonth = “02”
Case “Sep”
sMonth = “09”
End Select
newDate = sMonth + “/” + sDay + “/” + sYear
You’ll have to finish the ‘case’ statement to get all the months of course.
Ideally we could convert 30-Sep-2016 directly to a date and I tried that a bit and it didn’t work. Easier to just chop it up like I did above.
Best approach there is using the substring() function and then parse out the month and year. Then add in the “15” for the day and the “/” and you got it.
Dim newDate As String = “”
Dim sDate As String = “30-Sep-2016”
Dim sMonthInWords As String
Dim sYear As String
Dim sMonth As String = “”
Dim sDay As String = “15”
sMonthInWords = sDate.Substring(3, 3)
sYear = sDate.Substring(7, 4)
Select Case sMonthInWords
Case “Jan”
sMonth = “01”
Case “Feb”
sMonth = “02”
Case “Sep”
sMonth = “09”
End Select
newDate = sMonth + “/” + sDay + “/” + sYear
You’ll have to finish the ‘case’ statement to get all the months of course.
Ideally we could convert 30-Sep-2016 directly to a date and I tried that a bit and it didn’t work. Easier to just chop it up like I did above.