Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Mysql TimeStamp converter class
Author:
Jujhar Singh
Website:
http://sikhphotos.org
Submitted:
5/23/2005
Version:
VB.NET 2003
Compatibility:
VB.NET 2002, VB.NET 2003, VB.NET 2005
Category:
Date/Time
Views:
20316
A class to take the date given as a date type or string type convert it into yyyymmddhhmmss string for use in MYSQL SQL strings. Usage: Dim dateConvert As New mySQLlDate myDateString=dateConvert.convertDate(dateString) or myDateString=dateConvert.convertDate(dateTime) or myDateString=dateConvert.todaysDate
Declarations:
'none
Code:
Public Class mySQLlDate ' 'class to convert dates to mysql yyyymmddhhmmss strings, for use in your SQL's ' 'written by Jujhar Singh (Jujhar AT jujhar DOT com) 'vaheguru vaheguru vaheguru vahe jio 'this is just simple code and can be streamlined/enhanced, please feel free to use in your application. 'see http://creativecommons.org/licenses/by-sa/2.0/ if you need to use it under a different license then email me 'please let me know if you use this code anywhere or enhance it. 'God Bless Public Sub New() End Sub 'convertDate is an overloaded method that will handle string type dates and date type dates 'take the date given as a date type(from textboxes and convert into yyyymmddhhmmss string) Public Function convertDate(ByVal input As Date) Dim output As String Dim hour As String = CStr(input.Hour) Dim minute As String = CStr(input.Minute) Dim second As String = CStr(input.Second) Dim day As String = CStr(input.Day) Dim month As String = CStr(input.Month) If Len(CStr(input.Hour)) = 1 Then hour = "0" & input.Hour ElseIf Len(CStr(input.Hour)) = 0 Then hour = "00" End If If Len(CStr(input.Minute)) = 1 Then minute = "0" & input.Minute ElseIf Len(CStr(input.Minute)) = 0 Then minute = "00" End If If Len(CStr(input.Second)) = 1 Then second = "0" & input.Second ElseIf Len(CStr(input.Second)) = 0 Then second = "00" End If If Len(CStr(input.Day)) = 1 Then day = "0" & input.Day ElseIf Len(CStr(input.Day)) = 0 Then day = "00" End If If Len(CStr(input.Month)) = 1 Then month = "0" & input.Month ElseIf Len(CStr(input.Month)) = 0 Then month = "00" End If convertDate = CStr(input.Year & month & day & hour & minute & second) End Function 'take the date given as a string (from textboxes and convert into yyyymmddhhmmss string) Public Function convertDate(ByVal dateString As String) Dim input As Date Dim conv As Convert input = conv.ToDateTime(dateString) Dim hour As String = CStr(input.Hour) Dim minute As String = CStr(input.Minute) Dim second As String = CStr(input.Second) Dim day As String = CStr(input.Day) Dim month As String = CStr(input.Month) If Len(CStr(input.Hour)) = 1 Then hour = "0" & input.Hour ElseIf Len(CStr(input.Hour)) = 0 Then hour = "00" End If If Len(CStr(input.Minute)) = 1 Then minute = "0" & input.Minute ElseIf Len(CStr(input.Minute)) = 0 Then minute = "00" End If If Len(CStr(input.Second)) = 1 Then second = "0" & input.Second ElseIf Len(CStr(input.Second)) = 0 Then second = "00" End If If Len(CStr(input.Day)) = 1 Then day = "0" & input.Day ElseIf Len(CStr(input.Day)) = 0 Then day = "00" End If If Len(CStr(input.Month)) = 1 Then month = "0" & input.Month ElseIf Len(CStr(input.Month)) = 0 Then month = "00" End If convertDate = CStr(input.Year & month & day & hour & minute & second) End Function 'today's date as a string (from textboxes and convert into yyyymmddhhmmss string) Public Function todaysDate() Dim Input As Date = Date.Now Dim hour As String = CStr(Input.Hour) Dim minute As String = CStr(Input.Minute) Dim second As String = CStr(Input.Second) Dim day As String = CStr(Input.Day) Dim month As String = CStr(Input.Month) If Len(CStr(Input.Hour)) = 1 Then hour = "0" & Input.Hour ElseIf Len(CStr(Input.Hour)) = 0 Then hour = "00" End If If Len(CStr(Input.Minute)) = 1 Then minute = "0" & Input.Minute ElseIf Len(CStr(Input.Minute)) = 0 Then minute = "00" End If If Len(CStr(Input.Second)) = 1 Then second = "0" & Input.Second ElseIf Len(CStr(Input.Second)) = 0 Then second = "00" End If If Len(CStr(Input.Day)) = 1 Then day = "0" & Input.Day ElseIf Len(CStr(Input.Day)) = 0 Then day = "00" End If If Len(CStr(Input.Month)) = 1 Then month = "0" & Input.Month ElseIf Len(CStr(Input.Month)) = 0 Then month = "00" End If todaysDate = CStr(Input.Year & month & day & hour & minute & second) End Function End Class
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement