Logo 
Search:

VB.Net Articles

Submit Article
Home » Articles » VB.Net » DateTime FunctionsRSS Feeds

Convert Number to Date

Posted By: Vivek Patel     Category: VB.Net     Views: 15949

This is a utility function which converts date in number format to date datatype in vb.net. This function can also be used to convert string format date to date datatype in vb.net

'Purpose : This method would convert number format date data into date.
'Parameters : Number format string would be passed. Eg: 12281990
'Return Value : Date. Eg: 12/28/1990
Public Function Number2Date(ByVal lNum As Long) As Date
   Dim strNum As String = CStr(lNum)
   Dim iDay, iMon, iYear As Integer
   Dim ValidDate As Date
   
   Try
      'If date is not in valid format
      If strNum.Length = 7 Then
         strNum = "0" + strNum
      End If
 
      iMon = CInt(strNum.Substring(0, 2))
      iDay = CInt(strNum.Substring(2, 2))
      iYear = CInt(strNum.Substring(4, 4))
      ValidDate = New Date(iYear, iMon, iDay)
   Catch ex As Exception
      'ex.Message
   End Try

   Return ValidDate
End Function
  
Share: 


Didn't find what you were looking for? Find more on Convert Number to Date Or get search suggestion and latest updates.

Vivek Patel
Vivek Patel author of Convert Number to Date is from United States. Vivek Patel says

I have started working in .Net Technology since its beta release and lucky to got chance to work on .Net 1.1, 2.0 and now working on .Net 3.5. I have worked in both C# and VB.Net for Asp.net Projects. I can also provide Sharepoint development needs. I can efficiently switch role from Tech Lead and Developer. I have comprehensive knowledge of Asp.net Development. I have been award Microsoft Most Valuable Award twice in Asp.net Technology.

Blog: http://dotnetguts.blogspot.com

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!