Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2003
    Posts
    212

    Unanswered: Date format in ActiveX

    How do I get the date/time in the following format:

    2003-02-26 04:25:14
    or
    2003-02-26 14:25:14

    How do I get this format using only ActiveX commands?

    Thanks in advance.

  2. #2
    Join Date
    Sep 2003
    Posts
    522
    there is a way to change your regional settings with win api (it's been a while, I can't remember what I was bringing into vb to talk to that applet).

  3. #3
    Join Date
    Sep 2003
    Posts
    60
    You can use VB's Format command with the pre-defined date/time string like "GeneralDate" or something. It is based on the system's LocalID to provide localized time formats - or - if you want the date this way permanently you can "roll your own" formatting...
    Code:
    format(dtTargetDateTime, "YYYY-MM-DD hh:mm:ss")

  4. #4
    Join Date
    Sep 2003
    Posts
    212
    Originally posted by bill_dev
    You can use VB's Format command with the pre-defined date/time string like "GeneralDate" or something. It is based on the system's LocalID to provide localized time formats - or - if you want the date this way permanently you can "roll your own" formatting...
    Code:
    format(dtTargetDateTime, "YYYY-MM-DD hh:mm:ss")
    Well the purpose of this is because I want to write the date to a file while a DTS package is running, ie, some sort of logging. But I'm doing the loggin manually using AcitveX script in the DTS package.

    Now the problem is I want the Date in the above format, but the ActiveX script available in the DTS package tasks does not have the 'Format()' function.

    Using the codes available in the DTS ActiveX script tasks is it possible to write the date/time in the above format?

    Thanks,

  5. #5
    Join Date
    Sep 2003
    Posts
    60
    Yeah, VBSCRIPT only has the FormatDateTime() function. You can use it with the predefined formats I mentioned above or build your own formatting like this:

    sDate = year(dt) & "-" & month(dt) & "-" & day(dt) & _
    " " & formatdatetime(dt,vbLongTime)

    ...not sure what the longtime constant is. You'd need to look it up. Hope that helps.

  6. #6
    Join Date
    Sep 2003
    Posts
    212
    Originally posted by bill_dev
    Yeah, VBSCRIPT only has the FormatDateTime() function. You can use it with the predefined formats I mentioned above or build your own formatting like this:

    sDate = year(dt) & "-" & month(dt) & "-" & day(dt) & _
    " " & formatdatetime(dt,vbLongTime)

    ...not sure what the longtime constant is. You'd need to look it up. Hope that helps.
    Thanks for the tip.

    I ended up using a longer method that works.

    Dim datetime
    datetime = Year(Date) & "-"
    If Month(Date) < 10 Then
    datetime = datetime & "0"
    End If
    datetime = datetime & Month(Date) & "-"
    If Day(Date) < 10 Then
    datetime = datetime & "0"
    End If
    datetime = datetime & Day(Date) & " "
    If Hour(Time) < 10 Then
    datetime = datetime & "0"
    End If
    datetime = datetime & Hour(Time) & ":"
    If Minute(Time) < 10 Then
    datetime = datetime & "0"
    End If
    datetime = datetime & Minute(Time) & ":"
    If Second(Time) < 10 Then
    datetime = datetime & "0"
    End If
    datetime = datetime & Second(Time)

    Thanks again.

  7. #7
    Join Date
    Sep 2003
    Posts
    60
    Great. That's just an example, right? You'd want different variable names in the real thing...

Posting Permissions

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