Need help with date format

P

Phien-An Nguyen

Hello,

I have a TextBox1 binds to dateEnterred as datetime. My system date format
is m/d/yy. When I gave the value as string, "04/18/2008" to the
TextBox1.Text, it changed to "41/8/08".

Without changing the Date Format on the system and maintaining the datetime
datatype for dateEntered, how can I make the TextBox1.Text to bind value
"04/18/2008" instead of "41/8/08".


Thank you,

Phien-An
 
T

Thiago Macedo

try the .ToString method of datetime type:
datetime.ToString(format as string)

in case, datetime.ToString("MM/dd/YYYY")


Thiago
 
K

kimiraikkonen

Hello,

I have a TextBox1 binds to dateEnterred as datetime. My system date format
is m/d/yy. When I gave the value as string, "04/18/2008" to the
TextBox1.Text, it changed to "41/8/08".

Without changing the Date Format on the system and maintaining the datetime
datatype for dateEntered, how can I make the TextBox1.Text to bind value
"04/18/2008" instead of "41/8/08".

Thank you,

Phien-An

Hi,
DateString can provide you date omitted with hyphens "-", then you can
easily replace hyphens to slashes that matches your visiual desire.
So, place textbox named "textbox1" then here is your solution:

TextBox1.Text = DateString.ToString
TextBox1.Text = TextBox1.Text.Replace("-", "/")

Hope this helps,

Onur Güzel
 
M

Mark

Don't forget that there is a difference between lowercase m and uppercase M
on the date/time format. Looks like you had it using Minutes instead of
Months.
 
C

Cor Ligthert[MVP]

Mark,

In my idea you hit this one,

Cor

Mark said:
Don't forget that there is a difference between lowercase m and uppercase
M on the date/time format. Looks like you had it using Minutes instead of
Months.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top