locked
Month & Day get reversed when operating a service RRS feed

  • Question

  • I built 2 routines that log information to a file. One operates in the desktop in session 1 as an active monitor, and the other operates as a service in session 0. The log routine is identical in both routines, and logs to files with the filename as the current date in the format "yymmdd.log". The active monitor conforms to the defined format, but the service reverses the month and day, resulting in 2 different log files:

    12/06/10  03:16 PM                79 100612.log
    12/06/10  03:16 PM                72 101206.log

    I changed the format in both to "yyyymmdd.log", but the same thing occurred:

    12/06/10  04:47 PM               159 20100612.log
    12/06/10  04:49 PM               119 20101206.log

    The System Regional settings are set to English(United States), with the short date set to "MM/dd/yy". This discrepancy is somehow causing the service to fail, and I can't explain why. The only way to get the service running again is to delete all the log files, and restart the service. Just restarting the service does not correct the problem, and neither does rebooting the system.

    Computer is Dell Vostro-200 with Intel(R) Core2 Duo CPU E4500

    OS is Windows Vista Business SP2

    Tuesday, December 7, 2010 1:25 AM

Answers

  • Original Statement: Filename = WinDir & "system32\logfiles\DNS\" & Format(Date$, ("yyyymmdd")) & ".log" Your reply gave me a hint, and so I tried: Filename = WinDir & "system32\logfiles\DNS\" & Year(Now) & Month(Now) & Day(Now) & ".log" and that solved the problem. It still doesn't answer the question of why the month/day got reversed only while operating as a service, and only in Vista (and presumably Win7), but at least it works. Thanks
    Monday, December 13, 2010 6:56 PM

All replies

  • Hi,

    We need more background of the situation here.

    Which application is involved here? When it comes to Excel, when VBA copies from a .csv spreadsheet to an excel spreadsheet, the days/months in the date become reversed. You can use the following code:

    Dim dDate As Date
    dDate = DateSerial(Year(DateValue(StringDate)), _
              Month(DateValue(StringDate)), _
              Day(DateValue(StringDate)))
    Regards,
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
    Monday, December 13, 2010 10:26 AM
    Moderator
  • Original Statement: Filename = WinDir & "system32\logfiles\DNS\" & Format(Date$, ("yyyymmdd")) & ".log" Your reply gave me a hint, and so I tried: Filename = WinDir & "system32\logfiles\DNS\" & Year(Now) & Month(Now) & Day(Now) & ".log" and that solved the problem. It still doesn't answer the question of why the month/day got reversed only while operating as a service, and only in Vista (and presumably Win7), but at least it works. Thanks
    Monday, December 13, 2010 6:56 PM
  • Hi,

    For the root cause, you might need to open a new thread in MSDN forum.
    http://social.msdn.microsoft.com/Forums/en-US/categories 

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us.  Thank you for your understanding.

    Regards,


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
    Thursday, December 16, 2010 8:47 AM
    Moderator