Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output todays date digitally

Status
Not open for further replies.

kennyaidan

Programmer
Apr 9, 2003
54
IE
Hi,
I am just beginning to learn asp.net and i am learning the basics through some very simple examples. The following code just ouputs the todays date ie "4/12/2003"

<script runat=&quot;server&quot;>
Sub Page_Load(Sender as Object, E As EventArgs)

Dim time = now()
time = FormatDateTime(time, vbshortDate)
response.write (time)
End sub
</script>

Is it possible to print out the date in the following format ddmmyyyy ie &quot;20030412&quot;, if it is possible could someone point me in the right diresction
thanks
aidan
 
Dim time as Date = DateTime.Now
Dim formattedTime as string

formattedTime = time.year.toString() & time.month.ToString() & time.day.ToString()

Take advantage of your datatypes. Get in the habit of typing all your variables, rather than using objects (or variants in asp classic).

Also, forget you ever knew what Response.Write() was. Assign output to web controls.

lblMyLabel.Text = formattedTime

instead of

Response.Write(formattedTime)

It will make your code much more manageable.

-paul

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
Thanks Paul,
that worked great the output i got was &quot;2003412&quot; however would it be possible to get the output to be in the following format &quot;20030412&quot; because i am submitting the date into an database and in order for another file to work correctly i need all the dates i submit to be in that format ie &quot;20010101&quot;
thanks
aidan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top