Results 1 to 2 of 2

Thread: Problem displaying date and time correctly..

Hybrid View

  1. #1
    Join Date
    Nov 2004

    Problem displaying date and time correctly..

    I have a problem when I want to display a date with hours, minutes, seconds.

    This is the way it looks now.
    2005-7-16 12:14:6

    but it should be 2005-07-16 12:14:06 instead.

    How can I get the code to add a zero every time any of the numbers (month, date, hour, minute, second) is smaller than 10?

    I use this code to display everything when the date is retrieved from my db.


  2. #2
    Join Date
    Jan 2004
    Melbourne, Australia
    This is a common problem associated with dates. I usually write a small function to prefix a zero to the date/time part if necessary.
    Public Function PrefixZero(p_strDatePart)
        If Not IsNumeric(p_strDatePart) Then PrefixZero = p_strDatePart: Exit Function
        If CInt(p_strDatePart) < 10 Then
            PrefixZero = "0" & p_strDatePart
            PrefixZero = p_strDatePart
        End If
    End Function
    You can pass each date/time part to that function.
    Dim strHour
    strHour = PrefixZero(Hour(rs("reg_date")))

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles