convert string to datetime vb.net

前端 未结 4 1030
北海茫月
北海茫月 2021-01-24 14:15

i need to convert strings to date format. the requirement is if current month is selected, the date should be getdate. if any other month is selected then it should be first of

4条回答
  •  深忆病人
    2021-01-24 14:37

    You could use this function:

    Private Function GetDate(ByVal source As String) As DateTime
        Dim converted = DateTime.Parse(source)
        If (converted.Year.Equals(DateTime.Now.Year) And converted.Month.Equals(DateTime.Now.Month)) Then
            GetDate = DateTime.Now
        Else
            GetDate = converted
        End If
    End Function
    

    it could analysed passed month + year values like "April 2010".

提交回复
热议问题