[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Date Format

Posted on 2006-05-22
6
Medium Priority
?
964 Views
Last Modified: 2011-09-20
I have a script that generates a log file when users log into our Citrix Web Interface (terminal server application).  This was a custom script written where it's common to show dates as DD/MM/YYYY instead of MM/DD/YYYY like here in the U.S.  I have no experience with ASP.Net so I need some help altering this so it shows the date format as MM/DD/YYYY.  

Here is everything I have for this customization:

wiac.aspx
*****************************************************************************************
<%@ Page Language="vb" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>

<script language="VB" runat="Server">
Dim logReader As System.IO.StreamReader
Dim CSVWriter As System.IO.StreamWriter
Dim SearchTemp As Object
Dim iconLocation As String
Dim SelectPeriod As String
Dim RecordCount As Short
Dim CSVLocation As String
Dim TempDate As Date
Dim AppName As String
Dim LineOfText As String
Dim UserName As String
Dim SearchPeriod As Integer
Dim RemoteAddr As String
Dim LogonMode As String
Dim LogLocation As String
Dim GMTOffset As Double
Dim DateStamp As String
Dim IsSearch As String
Dim CSVWebPath As String
</script>

<%
' WILog.asp
' 4.x (Build 02)
' Copyright (c) 2003 - 2005 THOMAS@CITRIX4GE.de, Inc. All Rights Reserved.
'
'

' Must authenticate in order to see this sensitive information
If IsNothing(request.ServerVariables.GetValues("LOGON_USER")) Then
      Response.Status = "401 Access Denied"
      Response.End()
End If

%>

<HTML>
<head>
  <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
  <meta NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW, NOARCHIVE">
  <title>Citrix Web Interface log analyse center</title>

<style type="text/css">
<!--
.toolbarTitle
{
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 100%;
    font-weight: bold;
    color: #000000
}

.toolbarName
{
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 80%;
    font-weight: bold;
}

.toolbarText
{
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 80%;
}

.toolbarTextred
{
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 80%;
    color: #FF0000;
    font-weight: bold;
}

TD.toolbar
{
    background-color: #C8C8C8;

    background-image: url("../media/greygrad.gif");

    background-repeat: repeat-x;
}

TH.toolbar
{
    background-color: #C8C8C8;

    background-image: url("../media/greygrad.gif");

    background-repeat: repeat-x;
}

.csvlink
{
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 80%;
    color: #000000;
    text-decoration: none
}

-->
</style>


<head>
<body>

<table border="1" cellspacing="0" cellpadding="4" width="780">
  <tr>
    <td valign="top" class="toolbar" height="30" width="100%" colspan=2>
      <table border="0" width="100%" cellspacing="0" cellpadding="">
        <tr>          
        <td height="1"><img height="1" width="1" src="../media/spacer.gif" alt=""></td>        
        <td width="100%">
            <span class="toolbarTitle"><img height="1" width="5" src="../media/spacer.gif" alt="">Web Interface log analyse Center</span>
          </td>
          <td height="1"><A HREF="./"><img border="0" height="48" width="48" src="../media/site_icon.gif" alt="Back to Web Interface"></a></td>
      </tr>
      </table>

    </td>
  </tr>

  <tr><td width="100%" colspan=2 valign="top">

      <table border="0" width="100%" cellspacing="0" cellpadding="5">
      <tr>
          <td width=100 valign="top">
           <FONT FACE="Trebuchet MS, Verdana, Arial" SIZE="-1">
         <FORM method="post" action="wiac.aspx?Search=True" name="SubmitForm">
         <b>Search type:</b> <SELECT NAME="SearchType" SIZE=-1>
         <OPTION VALUE=0 SELECTED> All entries
         <OPTION VALUE=2> Last 12 Hours
         <OPTION VALUE=1> Last 24 Hours
         <OPTION VALUE=7> Last Week
         <OPTION VALUE=3> Last Quarter
         <OPTION VALUE=6> Last 6 months
         <OPTION VALUE=12> Last Year
         </SELECT>
        </td>

          <td width=680 valign=top rowspan="2">
            <table border=0 cellspacing=0 cellpadding=0 width=780><tr><td align=center><span class=toolbarName>The Web Interface log analyse center was downloaded @ <A HREF=http://www.citrix4ge.de/ target="top">www.CITRIX4GE.de</A></span>
            <br><span class=toolbarText>Thomas Koetzing copyright 2003-2005 | Last updated August 2005</span><br>
                <A HREF=http://www.citrix4ge.de/ target="top"><img border="0" vspace="4" height="55" width="238" src="wiac/logo.jpg" alt="Thomas Koetzing - SBC-Specialist"></a></td></tr></table>
          </td>
       </tr>

       <tr>
         <td valign=middle><INPUT type=submit value=Search name=SubmitButton></FORM></td>
         
      </tr>
     </table>

   </td>
</tr>

<tr>
   <td class=toolbar><span class="toolbarTitle">Messages</span></td>
</tr>

<tr>
  <td width="100%" valign=top>


<%
' Set Constants
' number of seconds after GMT in my timezone
' -------------------------------------------------------------------
GMTOffset = 1440

LogLocation = Server.MapPath("wiac/aclog.txt")
CSVLocation = Server.MapPath("wiac/aclog.csv")
iconLocation = Server.MapPath("wiac/logo.jpg")
CSVWebPath = "wiac/aclog.csv"


SearchTemp = request.Item("SearchType")
If SearchTemp = 0 Then SelectPeriod = "All entries"
If SearchTemp = 2 Then SelectPeriod = "Last 12 Hours"
If SearchTemp = 1 Then SelectPeriod = "Last 24 Hours"
If SearchTemp = 7 Then SelectPeriod = "Last Week"
If SearchTemp = 3 Then SelectPeriod = "Last Quarter"
If SearchTemp = 6 Then SelectPeriod = "Last 6 months"
If SearchTemp = 12 Then SelectPeriod = "Last Year"
IsSearch = request.Item("search")

If File.Exists(LogLocation) Then
      If File.Exists(iconLocation) Then
            ' check file existence
            ' -------------------------------------------------------------------
            
            If UCase(IsSearch) = "TRUE" Then
                  ' Reading all log entries
                  ' -------------------------------------------------------------------
                  logReader = new StreamReader(LogLocation)
                  CSVWriter = New StreamWriter(CSVLocation, true)
                  
                  TempDate = Now
                  If SearchTemp = 0 Then SearchPeriod = 0
                  If SearchTemp = 2 Then SearchPeriod = DateDiff(Microsoft.VisualBasic.DateInterval.Second, CDate("1/1/2003"), DateAdd(Microsoft.VisualBasic.DateInterval.Hour, -12, TempDate)) - GMTOffset
                  If SearchTemp = 1 Then SearchPeriod = DateDiff(Microsoft.VisualBasic.DateInterval.Second, CDate("1/1/2003"), DateAdd(Microsoft.VisualBasic.DateInterval.Day, -1, TempDate)) - GMTOffset
                  If SearchTemp = 7 Then SearchPeriod = DateDiff(Microsoft.VisualBasic.DateInterval.Second, CDate("1/1/2003"), DateAdd(Microsoft.VisualBasic.DateInterval.Day, -7, TempDate)) - GMTOffset
                  If SearchTemp = 3 Then SearchPeriod = DateDiff(Microsoft.VisualBasic.DateInterval.Second, CDate("1/1/2003"), DateAdd(Microsoft.VisualBasic.DateInterval.Quarter, -1, TempDate)) - GMTOffset
                  If SearchTemp = 6 Then SearchPeriod = DateDiff(Microsoft.VisualBasic.DateInterval.Second, CDate("1/1/2003"), DateAdd(Microsoft.VisualBasic.DateInterval.Month, -6, TempDate)) - GMTOffset
                  If SearchTemp = 12 Then SearchPeriod = DateDiff(Microsoft.VisualBasic.DateInterval.Second, CDate("1/1/2003"), DateAdd(Microsoft.VisualBasic.DateInterval.Month, -12, TempDate)) - GMTOffset
                  TempDate = DateAdd(Microsoft.VisualBasic.DateInterval.Second, SearchPeriod + GMTOffset, CDate("1/1/2003"))
                  
                  Response.Write("<img align=left vspace=8 hspace=8 height=32 width=32 src=../media/info.gif>")
                  Response.Write("<span class=toolbarName>Launched published applications since " & Microsoft.VisualBasic.Day(TempDate) & "/" & Month(TempDate) & "/" & Year(TempDate) & " " & FormatDateTime(TempDate, DateFormat.LongTime) & "</span>")
                  Response.Write("<br><span class=toolbarName>Selected Search type: </span><span class=toolbarTextred>" & SelectPeriod & "</span>")
                  Response.Write("<br><A HREF=""" & CSVWebPath & """class=csvlink>> Download the Web Interface log output as CSV file. <</A></td></tr><tr><td colspan=2><TABLE width=100% cellpadding=2 border=1><TR><TH width=150 class=toolbar><span class=toolbarName>Date and Time<span></TH><TH width=200 class=toolbar><span class=toolbarName>Domain and User</span></TH><TH width=100 class=toolbar><span class=toolbarName>Client IP Address</span></TH><TH width=100 class=toolbar><span class=toolbarName>Logon Mode<span></TH><TH width=230 class=toolbar><span class=toolbarName>Folder and Publish Application</span></TH></TR>")
                  
                  RecordCount = 0
                  
                  LineOfText = logReader.ReadLine()
                  While Not LineOfText Is Nothing                        
                        ' Get DateStamp
                        DateStamp = Left(LineOfText, InStr(LineOfText, ",") - 1)
                        LineOfText = Right(LineOfText, Len(CStr(LineOfText)) - Len(DateStamp) - 1)
                        If Int(CDbl(DateStamp)) > Int(SearchPeriod) Then
                              RecordCount = RecordCount + 1
                              
                              ' Get UserName
                              UserName = Left(LineOfText, InStr(LineOfText, ",") - 1)
                              LineOfText = Right(LineOfText, Len(CStr(LineOfText)) - Len(UserName) - 1)
                              
                              ' Get Remote_ADDR
                              RemoteAddr = Left(LineOfText, InStr(LineOfText, ",") - 1)
                              LineOfText = Right(LineOfText, Len(CStr(LineOfText)) - Len(RemoteAddr) - 1)
                              
                              ' Get AppName
                              AppName = Left(LineOfText, InStr(LineOfText, ",") - 1)
                              LineOfText = Right(LineOfText, Len(CStr(LineOfText)) - Len(AppName) - 1)                              
                              
                              ' Get LogonMode
                              LogonMode = Left(LineOfText, InStr(LineOfText, ",") - 1)
                              LineOfText = Right(LineOfText, Len(CStr(LineOfText)) - Len(LogonMode) - 1)
                              
                              ' Output
                              TempDate = DateAdd(Microsoft.VisualBasic.DateInterval.Second, CDbl(DateStamp) + GMTOffset, CDate("1/1/2003"))
                              Response.Write(("<TR><TD bgcolor=#00FFFFFF><span class=toolbarText>" & Microsoft.VisualBasic.Day(TempDate) & "/" & Month(TempDate) & "/" & Year(TempDate) & " " & FormatDateTime(TempDate, DateFormat.LongTime) & "</span></TD><TD bgcolor=#00FFFF><span class=toolbarText>" & UserName & "</span></TD><TD bgcolor=#00FFFF><span class=toolbarText>" & RemoteAddr & "</span></TD><TD bgcolor=#00FFFF><span class=toolbarText>" & LogonMode & "</span></TD><TD bgcolor=#00FFFF><span class=toolbarText>" & AppName & "</span></TD></TR>"))
                              CSVWriter.WriteLine(Microsoft.VisualBasic.Day(TempDate) & "/" & Month(TempDate) & "/" & Year(TempDate) & " " & FormatDateTime(TempDate, DateFormat.LongTime) & "," & UserName & "," & RemoteAddr & "," & LogonMode & "," & AppName)                              
                        End If
                        LineOfText = logReader.ReadLine()
                  End While
                  Response.Write("</TABLE>")
                  Response.Write("<img height=15 width=5 src=../media/spacer.gif><span class=toolbarName>" & RecordCount & " record(s) found.</span>")
                  If (RecordCount = 0) Then
                        Response.Write("<p><img align=left vspace=8 hspace=8 height=32 width=32 src=../media/warning.gif><span class=toolbarTextred>WARNING</span><br><span class=toolbarText>You might have chosen a bad time frame, try a different search type. If you are sure there has to be a result, then the most</span><br>")
                        Response.Write("<span class=toolbarText>common problem is missing file permissions for the <b>aclog.txt</b> file. Add User <b>IURS_MACHINE</b> and set <u>modify</u> permission.</span>")
                  End If
                  Response.Write("</td></tr></table></td></tr></table>")
                  
                  
                  ' tidy up
                  '-----------------------------------------------------------------------
                  logReader.Close()
                  CSVWriter.Close()                  
            End If
            
      Else
            Response.Write("<img align=left vspace=8 hspace=8 height=32 width=32 src=../media/error.gif><span class=toolbarTextred>ERROR</span><br><span class=toolbarText>Could not find the <b>logo.jpg</b> file in the site/wiac folder!</span><br>")
            Response.Write("<span class=toolbarText>The Web Interface log analyse center is free to use but please leave the logo in place, Thanks!</span>")
      End If
      
Else
      Response.Write("<img align=left vspace=8 hspace=8 height=32 width=32 src=../media/error.gif><span class=toolbarTextred>ERROR</span><br><span class=toolbarText>Could not find the log file at </span><span class=toolbarName>" & LogLocation & "</span><br>")
      Response.Write("<span class=toolbarText>Make sure you have created an empty <b>aclog.txt</b> file in the folder and set <u>modify</u> permissions for User <b>IURS_MACHINE</b>.</span>")
End If

%>


 
</body>
</html>
**************************************************************


wiac.cs
**************************************************************
<%
// wiac.cs
// Copyright (c) 2003 - 2005 CITRIX4GE, THOMAS@CITRIX4GE.DE
// for Web Interface 4.x
%>
<%@ Import Namespace="System.Globalization" %>
<%@ Import Namespace="System.IO" %>

<script runat="server">


//--------------------------------------------------------------------------
// Base settings
//--------------------------------------------------------------------------
int GMToffset = 1440;

//--------------------------------------------------------------------------
// get the system date and time and create a time stamp
//--------------------------------------------------------------------------
private String DayTime()
 {
 TimeSpan t = (DateTime.Now - new DateTime(2003, 1, 1));
 int TimeStamp  = (int) t.TotalSeconds - GMToffset;

 return Convert.ToString(TimeStamp);
 }


private void ACLogNow()
{
//--------------------------------------------------------------------------
// Set Logfile path
//--------------------------------------------------------------------------
String path = Server.MapPath("wiac/aclog.txt");


//--------------------------------------------------------------------------
// Get Web Interface values
//--------------------------------------------------------------------------
string logonMode = authGetUntrustedLogonType();

string wingAppName = Request.QueryString[QSTR_LAUNCH_APPLICATION];
string[] parts = wingAppName.Split('.');
wingAppName = parts[4];

AccessToken authToken = authGetPrimaryAccessToken();
string UserIdentity = authToken.getUserIdentity();

string wingCurrenFolder = userPrefs.getCurrentFolder();



//--------------------------------------------------------------------------
// Write to AC log file
//--------------------------------------------------------------------------

try {

    StreamWriter writer = new StreamWriter(path, true);
    writer.Write(DayTime() + ",");
    writer.Write(UserIdentity + ",");
    writer.Write(getClientAddress() + ",");
    writer.Write(wingCurrenFolder + "\\" + wingAppName + ",");
    writer.Write(logonMode + ",");
    writer.WriteLine();
    writer.Close();

   } catch (Exception ex) {

 }

}

</script>
****************************************************************************


So basically there are 2 parts to this:

1. When users log in it records their logon time & some other info in a text file
2. When I browse to a certain page of the web interface I am able to see & download this info into a csv file.

At both locations I would like the date format to be recorded as MM/DD/YYYY

Thanks for the help.
0
Comment
Question by:mgcIT
  • 4
  • 2
6 Comments
 
LVL 3

Expert Comment

by:jplevyak
ID: 16739540
Just call the .ToString("MM/dd/yyyy") method on the date to be recorded. You can pretty much format the data any way you want using this method and the correct set of formatting strings.

Check here for full reference (DateTime format Strings):
http://msdn2.microsoft.com/en-us/library/8kb3ddd4.aspx
0
 
LVL 18

Author Comment

by:mgcIT
ID: 16739665
Thanks for the response.  Can you please be a little more specific where I would put that method (again I have absolutely no experience with ASP.Net). Please just re-write the code where applicable.

Thanks
0
 
LVL 3

Expert Comment

by:jplevyak
ID: 16766038
The method would be called off any of the DateTime variables that you are creating the format from. For example:

CSVWriter.WriteLine(<b>Microsoft.VisualBasic.Day(TempDate) & "/" & Month(TempDate) & "/" & Year(TempDate)</b> & " " & FormatDateTime(TempDate, DateFormat.LongTime) & "," & UserName & "," & RemoteAddr & "," & LogonMode & "," & AppName)  

Would become...

CSVWriter.WriteLine(<b>TempDate.ToString("MM/dd/yyyy")</b> & " " & FormatDateTime(TempDate, DateFormat.LongTime) & "," & UserName & "," & RemoteAddr & "," & LogonMode & "," & AppName)  
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:jplevyak
ID: 16766042
Sorry, ignore the <b> tags in the sample. Thought I could include Html-formatting in the comments.

CSVWriter.WriteLine(Microsoft.VisualBasic.Day(TempDate) & "/" & Month(TempDate) & "/" & Year(TempDate) & " " & FormatDateTime(TempDate, DateFormat.LongTime) & "," & UserName & "," & RemoteAddr & "," & LogonMode & "," & AppName)  

Would become...

CSVWriter.WriteLine(TempDate.ToString("MM/dd/yyyy") & " " & FormatDateTime(TempDate, DateFormat.LongTime) & "," & UserName & "," & RemoteAddr & "," & LogonMode & "," & AppName)
0
 
LVL 18

Author Comment

by:mgcIT
ID: 16771499
ok what about on this method where the date is recorded into the .txt file?  How would I modify this?

//--------------------------------------------------------------------------
// get the system date and time and create a time stamp
//--------------------------------------------------------------------------
private String DayTime()
 {
 TimeSpan t = (DateTime.Now - new DateTime(2003, 1, 1));
 int TimeStamp  = (int) t.TotalSeconds - GMToffset;

 return Convert.ToString(TimeStamp);
 }
0
 
LVL 3

Accepted Solution

by:
jplevyak earned 2000 total points
ID: 16773933
The DayTime function is actually returning the difference of seconds between the current date and the 1st of 2003. If all you need to do is write the current date to the log file, like you explained, than you wouldn't even need this function. You can simply call the ToString("MM/dd/yyyy") method from the static DateTime.Now property within the writer portion of your code.

//--------------------------------------------------------------------------
// Write to AC log file
//--------------------------------------------------------------------------

try {

    StreamWriter writer = new StreamWriter(path, true);
    writer.Write(DateTime.Now.ToString("MM/dd/yyyy") + ",");
    writer.Write(UserIdentity + ",");
    writer.Write(getClientAddress() + ",");
    writer.Write(wingCurrenFolder + "\\" + wingAppName + ",");
    writer.Write(logonMode + ",");
    writer.WriteLine();
    writer.Close();

   } catch (Exception ex) {

 }
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month18 days, 10 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question