473,387 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

formatting time and date

cj
Is this the .net way?

Dim msgDate As Date = Now
TextBox1.Text = Format(msgDate, "yyMMdd") 'I want year month day 060306
TextBox2.Text = Format(msgDate, "HHmmss") 'I want 13:23:58

I didn't think .net encourages functions like format(var, string) any
more but I'm not sure what takes it's place.
Mar 6 '06 #1
2 1085

cj wrote:
Is this the .net way?

Dim msgDate As Date = Now
TextBox1.Text = Format(msgDate, "yyMMdd") 'I want year month day 060306
TextBox2.Text = Format(msgDate, "HHmmss") 'I want 13:23:58

I didn't think .net encourages functions like format(var, string) any
more but I'm not sure what takes it's place.


You might prefer

TextBox1.Text = msgDate.ToString("yyMMdd")
TextBox2.Text = msgDate.ToString("HH:mm:ss")

I suppose it could be argued that using the Date[Time]'s own ToString
is more 'the .net way'. "In general, if you want a string
representation of an object, ask its ToString to do the job" being the
principle at work.
--
Larry Lard
Replies to group please

Mar 6 '06 #2
cj
Yes, that is what I was looking for. I'd tried, well I thought I tried
that earlier but couldn't get it to work. Wasn't sure what I should be
doing so I thought I'd ask. Thanks Larry.

Oh, and I really don't prefer it but I'm trying to move forward with the
..net way of doing things. :) Lastly I see an error in my example. I
wrote I wanted 13:23:58 but I really wanted 132358 so I'll just remove
the colons.

Larry Lard wrote:
cj wrote:
Is this the .net way?

Dim msgDate As Date = Now
TextBox1.Text = Format(msgDate, "yyMMdd") 'I want year month day 060306
TextBox2.Text = Format(msgDate, "HHmmss") 'I want 13:23:58

I didn't think .net encourages functions like format(var, string) any
more but I'm not sure what takes it's place.


You might prefer

TextBox1.Text = msgDate.ToString("yyMMdd")
TextBox2.Text = msgDate.ToString("HH:mm:ss")

I suppose it could be argued that using the Date[Time]'s own ToString
is more 'the .net way'. "In general, if you want a string
representation of an object, ask its ToString to do the job" being the
principle at work.

Mar 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
4
by: deko | last post by:
I've heard it's best not to have any formatting specified for Table fields (except perhaps Currency), and instead set the formatting in the Form or Report. But what about Yes/No fields? When I...
4
by: hope | last post by:
Hi, How can I format a string field using Data Formatting Expression property in datagrid? For example: format last name from BROWN to Brown. Thanks
2
by: johndcal | last post by:
Hello All, I have a date value that I pull from a .csv file. After reading the file and storing the values in an array the value of the date could be found in $array, for example....
25
by: mdh | last post by:
Hi Group, Not looking for an answer, but more of an explanation. Thinking back to those heady days when you had the time to do them, may I ask this. Exercise 1-22 asks for a program to "fold"...
7
by: Middletree | last post by:
I am trying to display dates in a spreadsheet, but the dates need to be in a format that will allow them to be sorted in Excel. The datatype in the SQL Server database is datetime. In this case, I...
4
by: Ken Wigle | last post by:
All, I would be very grateful for any help on this question. I have an application in asp.net 2.0 where I dynamically create a datatable and then bind that to a gridview. Unfortunately, the...
7
by: christery | last post by:
Anyone got a clue to why ther is a T between date and time in the "formatted for sorting" or whatewer they call it, and a Z at the end after seconds- got it fixed for my cobol programmer by...
1
by: Cartoper | last post by:
How does one go about formatting the date/time string correctly to set the If-Modified-Since to the current date/time in an AJAX call? I know I need something like this: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.