www.webdeveloper.com
Results 1 to 8 of 8

Thread: Selecting Date and time

  1. #1
    Join Date
    Mar 2005
    Posts
    15

    Selecting Date and time

    I would like to retrieve the current date and time using asp.

    I then would like to take the yymm part from the date
    and the hhmm from the time field.

    I think you do this using the substr function?

    Would like the final result to look like:

    yymmhhmm as the field

    Any help is appreciated

    Thanks

  2. #2
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    The keyword Now will return the current date and time. Alternatively, you can use the Date and Time functions, respectively. VBScript has a bunch of handy date handling functions that we can use here.
    Code:
    Dim dteCurrDate, dteCurrTime 
    Dim strOutput
    dteCurrDate = Date
    dteCurrTime = Time
    
    strOutput = Right(CStr(Year(dteCurrDate)), 2) & _
                CStr(Month(dteCurrDate)) & _
                CStr(Hour(dteCurrTime)) & _
                CStr(Minute(dteCurrTime))
    
    Response.Write(strOutput)
    Note, hours are in 24-hour time. 3PM = 15.

    Give that a shot.

    Regards.

  3. #3
    Join Date
    Mar 2005
    Posts
    15
    Thanyou very much sir, it would have taken me the whole night tonight
    at ome to figure it out.

    I am just learning ASP and VB on the side, as I do mainframe work (dinasour)

    I have to read, look at examples.

    Thanks again

  4. #4
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298

  5. #5
    Join Date
    Mar 2005
    Posts
    15
    One more quick question.

    The month returns values from 1 - 12, how can I get say month 01,02,03...

    Also hiurs, minutes and second, like to get lead 0 in so I can make my key a
    uniform length

  6. #6
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    The way I do it is via a function I call prefixZero(...).
    Code:
    Dim dteCurrDate, dteCurrTime 
    Dim strOutput
    dteCurrDate = Date
    dteCurrTime = Time
    
    Public Function PrefixZero(num)
        Dim newNum
        If (CInt(num) < 10)
           PrefixZero = "0" & num
        Else
           PrefixZero = num
        End If
    End Function
    
    strOutput = Right(CStr(Year(dteCurrDate)), 2) & _
                PrefixZero(CStr(Month(dteCurrDate))) & _
                PrefixZero(CStr(Hour(dteCurrTime))) & _
                PrefixZero(CStr(Minute(dteCurrTime)))
    
    Response.Write(strOutput)
    That should work alright.

    Regards.

  7. #7
    Join Date
    Mar 2005
    Posts
    15
    Thanks, I had started to setup a select case, but this is much simpler

  8. #8
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298

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