Another Date question

Jamboree

New Member
Hi,<BR><BR>I'm still having many difficulties getting my head inside .NET, mainly because of the difficulty in finding adequete samples.<BR><BR>Here is some code for a classic asp page, if anybody has the time could you please show me the optimum way to code the .NET equivalent (pref. in VB) as a .aspx file.<BR><BR>If you would prefer to e-mail rather that post you can e-mail me the result at <BR> <BR> <BR> [ [email protected] ]<BR><BR><BR><BR><%@ language="VBScript" %><BR><%<BR>Option Explicit<BR>Response.Buffer = True<BR>Session.LCID = 3081<BR><BR><BR>Dim myDate<BR>Dim firstYearDay<BR>Dim lastWednesday<BR><BR>'Get the current time<BR>myDate = Now<BR><BR>firstYearDay = DateSerial(Year(myDate), Month(myDate), 1)<BR><BR>lastWednesday = DateAdd("d", -Weekday(myDate,4)+1, myDate)<BR>%><BR><BR><html><body><BR><BR><p><BR><BR>The first day of this year was: <%=FormatDateTime(firstYearDay, vbLongDate)%><br /><BR><BR>Last Wednesday's date was: <%=FormatDateTime(lastWednesday, vbLongDate)%><BR><BR></p><BR><BR></body></html><BR><BR><BR>Thanks.Here is the source code. I agree that the lack of examples on the Web is intimidating. The best bet, I've found, is to study the .NET Framework docs religiously. You have looked at those, no? That's where all of these DateTime functions can be found (DateTime is a class in the System namespace). Also, you might want to puruse the links at:<BR>http://www.4guysfromrolla.com/webtech/LearnMore/ASPPlus.asp<BR><BR><script language="vb" runat="server"><BR><BR> Sub Page_Load(source as Object, e as EventArgs)<BR><BR> Dim myDate as DateTime = DateTime.Now<BR> Dim firstYearDate as New DateTime(DateTime.Now.Year, DateTime.Now.Month, 1)<BR><BR> Dim lastWednesday as DateTime<BR> If myDate.DayOfWeek <= 3 then<BR> lastWednesday = myDate.AddDays(-7 + (3 - myDate.DayOfWeek))<BR> Else<BR> lastWednesday = myDate.AddDays(-(myDate.DayOfWeek - 3))<BR> End If<BR><BR><BR> lblFirstDayOfYear.Text = firstYearDate.ToLongDateString()<BR> lblLastWednesday.Text = lastWednesday.ToLongDateString()<BR><BR> End Sub<BR><BR></script><BR><BR><html><BR><body><BR><BR> The first day of this year was:<BR> <asp:label runat="server" id="lblFirstDayOfYear" /><br /> <BR><BR> Last Wednesday's date was:<BR> <asp:label runat="server" id="lblLastWednesday" /><br /> <BR><BR></body><BR></html> <BR><BR>The output on my computer when I just ran this:<BR><BR>The first day of this year was: Monday, January 01, 2001<BR>Last Wednesday's date was: Wednesday, January 17, 2001<BR><BR><BR>Happy Programming!.What are the rules for importing a namespace into your page.<BR><BR>I saw an example the other day where the developer wanted to use the Rnd and Randomize functions, but he had to import the Microsoft.VisualBasic.Compatability.VB6 namespace to have access to those functions.<BR><BR>Why don't I have to import the system namespace to be able to work with the DateTime class??? Is the system namespace included by default?<BR><BR>Thanks again.<BR><BR>DarrenThere are certain namespaces included by default. They are, off the top of my head:<BR><BR>System<BR>System.Collections<BR>System.Web<BR>System.Web.UI<BR><BR>You can always import other namespaces with the import directive:<BR><%@ Import Namespace="namespace_name" %><BR><BR>As far as generating random numbers with the .NET Framework, you should probably use the Random class of the System namespace... cleaner than importing some esoteric VB6 compatibility class, IMHO.<BR><BR>Happy Programming!
 
Back
Top