Results 1 to 16 of 16

Thread: Date On Server

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    nasik,india
    Posts
    909

    Red face Date On Server

    I Want To Get Date/time Of Server Machine From Another Machine Through Vb-code

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Date On Server

    This may help You.
    VB Code:
    1. Private Const NERR_SUCCESS As Long = 0&
    2. Private Const TIME_ZONE_ID_DAYLIGHT As Long = 2
    3.  
    4. Private Type TIME_OF_DAY_INFO
    5.    tod_elapsedt    As Long
    6.    tod_msecs       As Long
    7.    tod_hours       As Long
    8.    tod_mins        As Long
    9.    tod_secs        As Long
    10.    tod_hunds       As Long
    11.    tod_timezone    As Long
    12.    tod_tinterval   As Long
    13.    tod_day         As Long
    14.    tod_month       As Long
    15.    tod_year        As Long
    16.    tod_weekday     As Long
    17. End Type
    18.  
    19. Private Type SYSTEMTIME
    20.    wYear         As Integer
    21.    wMonth        As Integer
    22.    wDayOfWeek    As Integer
    23.    wDay          As Integer
    24.    wHour         As Integer
    25.    wMinute       As Integer
    26.    wSecond       As Integer
    27.    wMilliseconds As Integer
    28. End Type
    29.  
    30. Private Type TIME_ZONE_INFORMATION
    31.    bias           As Long
    32.    StandardName(0 To 63) As Byte  'unicode (0-based)
    33.    StandardDate   As SYSTEMTIME
    34.    StandardBias   As Long
    35.    DaylightName(0 To 63) As Byte  'unicode (0-based)
    36.    DaylightDate   As SYSTEMTIME
    37.    DaylightBias   As Long
    38. End Type
    39.  
    40. Private Declare Function NetRemoteTOD Lib "Netapi32" _
    41.   (UncServerName As Byte, _
    42.    BufferPtr As Long) As Long
    43.  
    44. Private Declare Function NetApiBufferFree Lib "Netapi32" _
    45.   (ByVal lpBuffer As Long) As Long
    46.  
    47. Private Declare Sub CopyMemory Lib "kernel32" _
    48.    Alias "RtlMoveMemory" _
    49.   (pTo As Any, uFrom As Any, _
    50.    ByVal lSize As Long)
    51.  
    52. Private Declare Function GetTimeZoneInformation Lib "kernel32" _
    53.   (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
    54.    
    55. Private Declare Function SystemTimeToTzSpecificLocalTime Lib "kernel32" _
    56.   (lpTimeZoneInformation As TIME_ZONE_INFORMATION, _
    57.    lpUniversalTime As SYSTEMTIME, _
    58.    lpLocalTime As SYSTEMTIME) As Long
    59.    
    60.    
    61. Private Sub Command1_Click()
    62.  
    63.    Dim server_date As TIME_OF_DAY_INFO
    64.    Dim sServer As String
    65.    
    66.    List1.Clear
    67.    List2.Clear
    68.  
    69.   'Specify the server and pass to GetRemoteTOD.
    70.  
    71.   'The function returns the TIME_OF_DAY_INFO
    72.   'data adjusted to accomodate the local
    73.   'machine's regional location
    74.  
    75.   'Naturally, change the machine names to suit.
    76.    sServer = "\\vbnetdev"
    77.    server_date = GetRemoteTOD(sServer)
    78.    DisplayData List1, server_date
    79.  
    80.    sServer = "\\laptop2000"
    81.    server_date = GetRemoteTOD(sServer)
    82.    DisplayData List2, server_date
    83.  
    84. End Sub
    85.  
    86.  
    87. Private Function GetRemoteTOD(ByVal sServer As String) As TIME_OF_DAY_INFO
    88.  
    89.    Dim success       As Long
    90.    Dim bServer()     As Byte
    91.    Dim tod           As TIME_OF_DAY_INFO
    92.    Dim systime_utc   As SYSTEMTIME
    93.    Dim systime_local As SYSTEMTIME
    94.    Dim tzi           As TIME_ZONE_INFORMATION
    95.    Dim bufptr        As Long
    96.  
    97.   'A null passed as sServer retrieves
    98.   'the date for the local machine. If
    99.   'sServer is null, no slashes are added.
    100.    If sServer <> vbNullChar Then
    101.    
    102.      'If a server name was specified,
    103.      'assure it has leading double slashes
    104.       If Left$(sServer, 2) <> "\\" Then
    105.          bServer = "\\" & sServer & vbNullChar
    106.       Else
    107.          bServer = sServer & vbNullChar
    108.       End If
    109.      
    110.    Else
    111.    
    112.      'null or empty string was passed
    113.       bServer = sServer & vbNullChar
    114.    
    115.    End If
    116.    
    117.   'get the time of day (TOD) from the specified server
    118.    If NetRemoteTOD(bServer(0), bufptr) = NERR_SUCCESS Then
    119.  
    120.      'copy the buffer into a
    121.      'TIME_OF_DAY_INFO structure
    122.       CopyMemory tod, ByVal bufptr, LenB(tod)
    123.  
    124.      'get the time zone data for the local machine
    125.       Call GetTimeZoneInformation(tzi)
    126.  
    127.      'assign TIME_OF_DAY_INFO members to
    128.      'the SYSTEMTIME structure and call
    129.      'SystemTimeToTzSpecificLocalTime to
    130.      'convert the UTC dates in
    131.      'TIME_OF_DAY_INFO to local dates
    132.       With systime_utc
    133.          .wDay = tod.tod_day
    134.          .wDayOfWeek = tod.tod_weekday
    135.          .wMonth = tod.tod_month
    136.          .wYear = tod.tod_year
    137.          .wHour = tod.tod_hours
    138.          .wMinute = tod.tod_mins
    139.          .wSecond = tod.tod_secs
    140.       End With
    141.      
    142.      'convert time in Coordinated Universal Time
    143.      '(UTC) to the time zone's corresponding
    144.      'local time. Passing a "null" TIME_ZONE_INFORMATION
    145.      '(tzi) causes the function to use the currently
    146.      'active time zone on the local machine.
    147.       Call SystemTimeToTzSpecificLocalTime(tzi, systime_utc, systime_local)
    148.  
    149.      'reassign the converted date members to
    150.      'the TIME_OF_DAY_INFO structure returned
    151.      'from the function
    152.       With tod
    153.          .tod_mins = systime_local.wMinute
    154.          .tod_hours = systime_local.wHour
    155.          .tod_secs = systime_local.wSecond
    156.          .tod_day = systime_local.wDay
    157.          .tod_month = systime_local.wMonth
    158.          .tod_year = systime_local.wYear
    159.          .tod_weekday = systime_local.wDayOfWeek
    160.       End With
    161.      
    162.    End If
    163.    
    164.    Call NetApiBufferFree(bufptr)
    165.    
    166.   'return the TIME_OF_DAY_INFO structure
    167.    GetRemoteTOD = tod
    168.  
    169. End Function
    170.  
    171.  
    172. Private Sub DisplayData(lst As ListBox, server_date As TIME_OF_DAY_INFO)
    173.  
    174.    Dim newtime  As Date
    175.    
    176.   'show the data returned
    177.    With lst
    178.       .AddItem server_date.tod_timezone
    179.       .AddItem server_date.tod_tinterval
    180.       .AddItem ""
    181.       .AddItem server_date.tod_elapsedt
    182.       .AddItem server_date.tod_msecs
    183.       .AddItem ""
    184.       .AddItem server_date.tod_hours
    185.       .AddItem server_date.tod_mins
    186.       .AddItem server_date.tod_secs
    187.       .AddItem server_date.tod_hunds
    188.       .AddItem ""
    189.       .AddItem server_date.tod_day
    190.       .AddItem server_date.tod_month
    191.       .AddItem server_date.tod_year
    192.       .AddItem server_date.tod_weekday
    193.       .AddItem ""
    194.  
    195.       'Some dates for comparison.
    196.      
    197.       'The first shows calculating the
    198.       'date using the tod_elapsedt member.
    199.       'tod_elapsedt is a value that contains
    200.       'the number of seconds since
    201.       '00:00:00, January 1, 1970, GMT.
    202.        newtime = DateAdd("s", server_date.tod_elapsedt, #1/1/1970#)
    203.       .AddItem newtime
    204.      
    205.       'Since tod_elapsedt is based on GMT (UTC),
    206.       'the next date applies the tod_timezone
    207.       'offset to adjust the date to the local time.
    208.        newtime = DateAdd("n", -server_date.tod_timezone, newtime)
    209.       .AddItem newtime
    210.      
    211.    End With
    212.    
    213.   'Now shows the local machine's date
    214.   'and time as per the local machine's
    215.   'regional short date/short time formats
    216.    Label1.Caption = Now
    217.      
    218. End Sub
    219.  
    220.  
    221. Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    222.    
    223.    On Error Resume Next
    224.    List2.ListIndex = List1.ListIndex
    225.    
    226. End Sub
    227.  
    228.  
    229. Private Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    230.  
    231.    On Error Resume Next
    232.    List2.ListIndex = List1.ListIndex
    233.    
    234. End Sub
    235.  
    236.  
    237. Private Sub List2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    238.  
    239.    On Error Resume Next
    240.    List1.ListIndex = List2.ListIndex
    241.  
    242. End Sub
    243.  
    244. Private Sub List2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    245.  
    246.    On Error Resume Next
    247.    List2.ListIndex = List2.ListIndex
    248.    
    249. End Sub

    If helped than mark this as resolved

  3. #3
    Lively Member
    Join Date
    Aug 2006
    Posts
    69

    Red face Re: Date On Server

    i just don't understand for long-code vb script that "danasegarane" wrote. maybe i can give u more simple answer.

    first:
    if u have simple db like MS-Access in your server, u can open it and send a sql command like "select now() as sysdate"...then u can pick-up a "sysdate" value as a server-time.

    second:
    create a simple class-module and put on server which send value of DATE function. when u call that program, it will sent back a date value...and u get it

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    nasik,india
    Posts
    909

    Re: Date On Server

    "danasegarane "
    it helps me.
    but my server is novell server. and it gives me error.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    nasik,india
    Posts
    909

    Re: Date On Server

    And sbudhisatrio , can you give me example, or can you tell me in detail ?

  6. #6
    Lively Member
    Join Date
    Aug 2006
    Posts
    69

    Re: Date On Server

    assuming that:
    1. you already open an .MDB access
    2. gDB as an opened database
    3. create a command button with "cmdGETDATE" name

    the code.....

    Private Sub cmdGETDATE_Click()
    Date = SERVER_DATE 'Set the local machine date same as Server date
    End Sub

    Function SERVER_DATE() as Date
    Dim vRS as Recordset
    set vRS = gDB.OpenRecordset("select now() as sysdate", dbOpenSnapshot)
    SERVER_DATE = vRS("sysdate")
    End Function

    can this one solve your problem....?

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    nasik,india
    Posts
    909

    Re: Date On Server

    no, this code gives me system date , i want server's current date where my database is located.

  8. #8
    Lively Member
    Join Date
    Aug 2006
    Posts
    69

    Re: Date On Server

    where u put ur database...i think u put it on server...

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    nasik,india
    Posts
    909

    Re: Date On Server

    yes.

  10. #10
    Lively Member
    Join Date
    Aug 2006
    Posts
    69

    Re: Date On Server

    it will sent u a server system-date...

    try to change your server date for a while and make it different with your client date...and try run again that program. It will change your client-date same as your server date.

    or define one variable with date type to receive SERVER_DATE value...if you just want to save server_date in a date variable

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    nasik,india
    Posts
    909

    Re: Date On Server

    i have tried this, but still it gives me system date.

  12. #12
    Lively Member
    Join Date
    Aug 2006
    Posts
    69

    Re: Date On Server

    which one of system date...client or server? and where u run that program...client or server?

    if ur database is put on server...all query-result will taken from server environment, including date/time system.

    my application is running well...i'm using an ORACLE database on server...under a certain circumstance date in all the client will push same as server-date. that's the part of my first step when client running the application...and i can keep all client-date in my office always same as server

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    nasik,india
    Posts
    909

    Re: Date On Server

    system date of client machine, where my program is running.

  14. #14
    Lively Member
    Join Date
    Aug 2006
    Posts
    69

    Re: Date On Server

    can u give me ur e-mail address...i will sent you moer detail for all of this

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    nasik,india
    Posts
    909

    Re: Date On Server

    [email protected]
    or
    [email protected]
    plsss help me.
    thanks.

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    nasik,india
    Posts
    909

    Re: Date On Server

    "sbudhisatrio "
    i got your mail.
    Thank you.
    but that code still displays client machine date.
    do you know about function "NetRemoteTOD" ?
    it gives remote machine date,but not novell server !
    WHETHER YOU SUCCEED OR FAIL IS NOT AS IMPORTANT AS WHETHER YOU TRIED YOUR BEST

Posting Permissions

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



Click Here to Expand Forum to Full Width