Results 1 to 4 of 4

Thread: Date - very simple.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954

    Date - very simple.

    I am trying to learn c#, and have a VERY simple question. How do you display the current date inside of a td tag, also how do you display the current time inside a td tag?

    Thanks.

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    You can get the current datetime with DateTime.Now, and the ToString() method accepts many different format patterns to display date and time pretty much as many ways as you can think of:
    Code:
    <table>
    	<tr>
    		<td><%= DateTime.Now.ToString("HH:mm MM/dd/yyyy") %></td>
    	</tr>
    </table>

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    It worked, although I am confused. If this is c#, where is the ;?

  4. #4
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    It's just the way those tags work. You're not sticking a line of code in there, it's an expression that must evaluate to a value. This line fails
    PHP Code:
    <%= Response.Write("Hello World") %> 
    because Response.Write("Hello World") does not evaluate to a value. This line also fails:
    PHP Code:
    <% Response.Write("Hello World") %> 
    because a semi-colon is missing(assuming you declared C# to be the language for the page). This line works
    PHP Code:
    <% Response.Write("Hello World"); %> 
    Not sure if this made it clearer or cloudier for ya, maybe someone else has a better explanation.

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