Wednesday, March 28, 2012
text date conversion
I have a datepicker control that's providing dates in the format dd/mm/yyyy
(UK).
I want to convert this to "yyyy-mm-dd" to store as a text field in my
database (had lots of problems with date conversions using "proper" data
fields).
I used to use ASP, and it was easy, using a combination of Left() Mid() and
Right(), but I can't work out how to do this conversion in C#.
Help appreciated!
Cheers
DanDateTime.ToString("yyyy-MM-dd");
"dhnriverside" <dan@.musoswire.com> wrote in message
news:F96893C8-D39B-4207-B3C9-861A42594CD5@.microsoft.com...
Hi peeps
I have a datepicker control that's providing dates in the format dd/mm/yyyy
(UK).
I want to convert this to "yyyy-mm-dd" to store as a text field in my
database (had lots of problems with date conversions using "proper" data
fields).
I used to use ASP, and it was easy, using a combination of Left() Mid() and
Right(), but I can't work out how to do this conversion in C#.
Help appreciated!
Cheers
Dan
Easy,
Split the string "mm/dd/yyyy" into an array using the delimiter "/" so that
you get:
[mm]
[dd]
[yyyy]
Then swap array positions so you get:
[yyyy]
[mm]
[dd]
Then join the array using the "-" character.
Why you would choose to store DATES as STRINGS is beyond me (just sounds
like a really, really newbie solution)...but if it floats your boat, then
there's your solution.
"dhnriverside" wrote:
> Hi peeps
> I have a datepicker control that's providing dates in the format dd/mm/yyy
y
> (UK).
> I want to convert this to "yyyy-mm-dd" to store as a text field in my
> database (had lots of problems with date conversions using "proper" data
> fields).
> I used to use ASP, and it was easy, using a combination of Left() Mid() an
d
> Right(), but I can't work out how to do this conversion in C#.
> Help appreciated!
> Cheers
>
> Dan
Hi Charles
Thanks for that. Yeah it was very newbie. The original system was written
with Access/ASP and as I said I had tremendous trouble with pulling dates ou
t
the database.
Sussed that now, but im writing V2, it's just easier to continue with this
system than converting allllll the data :o)
Cheers for the answer!
Dan
"Charles Chen" wrote:
> Easy,
> Split the string "mm/dd/yyyy" into an array using the delimiter "/" so tha
t
> you get:
> [mm]
> [dd]
> [yyyy]
> Then swap array positions so you get:
> [yyyy]
> [mm]
> [dd]
> Then join the array using the "-" character.
> Why you would choose to store DATES as STRINGS is beyond me (just sounds
> like a really, really newbie solution)...but if it floats your boat, then
> there's your solution.
> "dhnriverside" wrote:
>
Dan,
You could always use the build in formatting on the DateTime object.
string s = "25/12/2004"
DateTime d = DateTime.ParseExact( s, "d/M/yyyy", null );
Now the variable 'd' will hold the date exactly as Dec 25, 2004.
You can get the date back out in any format you want using the .ToString()
method.
Console.WriteLine( d.ToString( "yyyy-MM-dd" ) )
Here are a couple links for DateTime formatting. These are gem pages for
working with any DateTime formatting issues.
http://msdn.microsoft.com/library/d...rmatstrings.asp
http://msdn.microsoft.com/library/d...rmatstrings.asp
Happy formatting!
bill
"dhnriverside" <dan@.musoswire.com> wrote in message
news:F96893C8-D39B-4207-B3C9-861A42594CD5@.microsoft.com...
> Hi peeps
> I have a datepicker control that's providing dates in the format
dd/mm/yyyy
> (UK).
> I want to convert this to "yyyy-mm-dd" to store as a text field in my
> database (had lots of problems with date conversions using "proper" data
> fields).
> I used to use ASP, and it was easy, using a combination of Left() Mid()
and
> Right(), but I can't work out how to do this conversion in C#.
> Help appreciated!
> Cheers
>
> Dan
text date conversion
I have a datepicker control that's providing dates in the format dd/mm/yyyy
(UK).
I want to convert this to "yyyy-mm-dd" to store as a text field in my
database (had lots of problems with date conversions using "proper" data
fields).
I used to use ASP, and it was easy, using a combination of Left() Mid() and
Right(), but I can't work out how to do this conversion in C#.
Help appreciated!
Cheers
DanDateTime.ToString("yyyy-MM-dd");
"dhnriverside" <dan@.musoswire.com> wrote in message
news:F96893C8-D39B-4207-B3C9-861A42594CD5@.microsoft.com...
Hi peeps
I have a datepicker control that's providing dates in the format dd/mm/yyyy
(UK).
I want to convert this to "yyyy-mm-dd" to store as a text field in my
database (had lots of problems with date conversions using "proper" data
fields).
I used to use ASP, and it was easy, using a combination of Left() Mid() and
Right(), but I can't work out how to do this conversion in C#.
Help appreciated!
Cheers
Dan
Easy,
Split the string "mm/dd/yyyy" into an array using the delimiter "/" so that
you get:
[mm]
[dd]
[yyyy]
Then swap array positions so you get:
[yyyy]
[mm]
[dd]
Then join the array using the "-" character.
Why you would choose to store DATES as STRINGS is beyond me (just sounds
like a really, really newbie solution)...but if it floats your boat, then
there's your solution.
"dhnriverside" wrote:
> Hi peeps
> I have a datepicker control that's providing dates in the format dd/mm/yyyy
> (UK).
> I want to convert this to "yyyy-mm-dd" to store as a text field in my
> database (had lots of problems with date conversions using "proper" data
> fields).
> I used to use ASP, and it was easy, using a combination of Left() Mid() and
> Right(), but I can't work out how to do this conversion in C#.
> Help appreciated!
> Cheers
>
> Dan
Hi Charles
Thanks for that. Yeah it was very newbie. The original system was written
with Access/ASP and as I said I had tremendous trouble with pulling dates out
the database.
Sussed that now, but im writing V2, it's just easier to continue with this
system than converting allllll the data :o)
Cheers for the answer!
Dan
"Charles Chen" wrote:
> Easy,
> Split the string "mm/dd/yyyy" into an array using the delimiter "/" so that
> you get:
> [mm]
> [dd]
> [yyyy]
> Then swap array positions so you get:
> [yyyy]
> [mm]
> [dd]
> Then join the array using the "-" character.
> Why you would choose to store DATES as STRINGS is beyond me (just sounds
> like a really, really newbie solution)...but if it floats your boat, then
> there's your solution.
> "dhnriverside" wrote:
> > Hi peeps
> > I have a datepicker control that's providing dates in the format dd/mm/yyyy
> > (UK).
> > I want to convert this to "yyyy-mm-dd" to store as a text field in my
> > database (had lots of problems with date conversions using "proper" data
> > fields).
> > I used to use ASP, and it was easy, using a combination of Left() Mid() and
> > Right(), but I can't work out how to do this conversion in C#.
> > Help appreciated!
> > Cheers
> > Dan
Dan,
You could always use the build in formatting on the DateTime object.
string s = "25/12/2004"
DateTime d = DateTime.ParseExact( s, "d/M/yyyy", null );
Now the variable 'd' will hold the date exactly as Dec 25, 2004.
You can get the date back out in any format you want using the .ToString()
method.
Console.WriteLine( d.ToString( "yyyy-MM-dd" ) )
Here are a couple links for DateTime formatting. These are gem pages for
working with any DateTime formatting issues.
http://msdn.microsoft.com/library/d...rmatstrings.asp
http://msdn.microsoft.com/library/d...rmatstrings.asp
Happy formatting!
bill
"dhnriverside" <dan@.musoswire.com> wrote in message
news:F96893C8-D39B-4207-B3C9-861A42594CD5@.microsoft.com...
> Hi peeps
> I have a datepicker control that's providing dates in the format
dd/mm/yyyy
> (UK).
> I want to convert this to "yyyy-mm-dd" to store as a text field in my
> database (had lots of problems with date conversions using "proper" data
> fields).
> I used to use ASP, and it was easy, using a combination of Left() Mid()
and
> Right(), but I can't work out how to do this conversion in C#.
> Help appreciated!
> Cheers
>
> Dan
Monday, March 26, 2012
text file format
this format which I'm close but not exactly there yet.
format I need:
1234569 BMW
1253252Mercedes
9876522 Lexus
9858252 Jaguar
I'm getting this format:
1234569 BMW
1253252 Mercedes
9876522 Lexus
9858252 Jaguar
here is my code I'm using to write the lines in the text file
string CarSales = string.Format("{0,-9}{1,-8}", VINNumber, CarMake);
file.WriteFile(CarSales);
am I missing something?I got it working I removed the (-) sign.
instead of this:
string CarSales = string.Format("{0,-9}{1,-8}", VINNumber, CarMake);
i did this:
string CarSales = string.Format("{0,9}{1,8}", VINNumber, CarMake);
and now the file lines up correctly
"igotyourdotnet" wrote:
> I need to create a text file which I can get working but i need it to be i
n
> this format which I'm close but not exactly there yet.
> format I need:
> 1234569 BMW
> 1253252Mercedes
> 9876522 Lexus
> 9858252 Jaguar
> I'm getting this format:
> 1234569 BMW
> 1253252 Mercedes
> 9876522 Lexus
> 9858252 Jaguar
> here is my code I'm using to write the lines in the text file
> string CarSales = string.Format("{0,-9}{1,-8}", VINNumber, CarMake);
> file.WriteFile(CarSales);
> am I missing something?
>
>
text file format
this format which I'm close but not exactly there yet.
format I need:
1234569 BMW
1253252Mercedes
9876522 Lexus
9858252 Jaguar
I'm getting this format:
1234569 BMW
1253252 Mercedes
9876522 Lexus
9858252 Jaguar
here is my code I'm using to write the lines in the text file
string CarSales = string.Format("{0,-9}{1,-8}", VINNumber, CarMake);
file.WriteFile(CarSales);
am I missing something?I got it working I removed the (-) sign.
instead of this:
string CarSales = string.Format("{0,-9}{1,-8}", VINNumber, CarMake);
i did this:
string CarSales = string.Format("{0,9}{1,8}", VINNumber, CarMake);
and now the file lines up correctly
"igotyourdotnet" wrote:
Quote:
Originally Posted by
I need to create a text file which I can get working but i need it to be in
this format which I'm close but not exactly there yet.
>
format I need:
1234569 BMW
1253252Mercedes
9876522 Lexus
9858252 Jaguar
>
I'm getting this format:
1234569 BMW
1253252 Mercedes
9876522 Lexus
9858252 Jaguar
>
here is my code I'm using to write the lines in the text file
string CarSales = string.Format("{0,-9}{1,-8}", VINNumber, CarMake);
file.WriteFile(CarSales);
>
am I missing something?
>
>
>
>
Text Format String - Please help
I need to display a DateTime field in 'mm/dd/yyyy' in a DataGrid.. On
myGrid1 - Properties - Columns - myColumn1 - Text format string:
I tried to put 'mm/dd/yyyy' in there and it displays 'mm/dd/yyyy' in stead
of '04/10/2001'. I know I didn't do it right. Please let me know what's the
correct way to display a 'mm/dd/yyyy' format for a DateTime coulmn.
Thanks.
Eddymake sure ur page Culture is set right
"Eddy Soeparmin" <esoeparmin@.clientprofiles.com> wrote in message
news:udPQR07RDHA.2008@.TK2MSFTNGP11.phx.gbl...
> Hi,
> I need to display a DateTime field in 'mm/dd/yyyy' in a DataGrid.. On
> myGrid1 - Properties - Columns - myColumn1 - Text format string:
> I tried to put 'mm/dd/yyyy' in there and it displays 'mm/dd/yyyy' in stead
> of '04/10/2001'. I know I didn't do it right. Please let me know what's
the
> correct way to display a 'mm/dd/yyyy' format for a DateTime coulmn.
> Thanks.
> Eddy
Hi Vincent,
> make sure ur page Culture is set right
I don't really understand what you mean by that, would you please explain
more specific in detail? I'm very new in this area. Is there something that
I have to do in VS.Net? or IE? Please advice.
Thanks.
"Vincent V" <vincentv@.-n0-5pam-optushome.com.au> wrote in message
news:O6fD6H8RDHA.304@.tk2msftngp13.phx.gbl...
> make sure ur page Culture is set right
> "Eddy Soeparmin" <esoeparmin@.clientprofiles.com> wrote in message
> news:udPQR07RDHA.2008@.TK2MSFTNGP11.phx.gbl...
> > Hi,
> > I need to display a DateTime field in 'mm/dd/yyyy' in a DataGrid.. On
> > myGrid1 - Properties - Columns - myColumn1 - Text format string:
> > I tried to put 'mm/dd/yyyy' in there and it displays 'mm/dd/yyyy' in
stead
> > of '04/10/2001'. I know I didn't do it right. Please let me know what's
> the
> > correct way to display a 'mm/dd/yyyy' format for a DateTime coulmn.
> > Thanks.
> > Eddy
Eddy,
I found myself having this problem the other day and
couldn't find any documentation in the MSDN other than for
numbers. Here is what you need to put in the format
string:
{0:mm/dd/yyyy}
Also,
http://asp.net/ is a really good site for anything related
to ASP .NET or .NET in general. The people in the Forums
there are very helpful and usually can answer my questions
within an hour.
>--Original Message--
>Hi,
>I need to display a DateTime field in 'mm/dd/yyyy' in a
DataGrid.. On
>myGrid1 - Properties - Columns - myColumn1 - Text format
string:
>I tried to put 'mm/dd/yyyy' in there and it
displays 'mm/dd/yyyy' in stead
>of '04/10/2001'. I know I didn't do it right. Please let
me know what's the
>correct way to display a 'mm/dd/yyyy' format for a
DateTime coulmn.
>Thanks.
>Eddy
>
>.
Vincent,
Try using the format "{0:MM/dd/yyyy}". Also, check the Help section within
the DataGrid Property Builder dialog box. It will provide you with more
information about the format modifiers.
Charlie Nilsson [msft]
Visual Studio Update
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
-------
> From: "Eddy Soeparmin" <esoeparmin@.clientprofiles.com>
> Subject: Text Format String - Please help
> Date: Fri, 11 Jul 2003 11:03:09 -0400
> Lines: 14
> X-Priority: 3
> X-MSMail-Priority: Normal
> X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
> Message-ID: <udPQR07RDHA.2008@.TK2MSFTNGP11.phx.gbl>
> Newsgroups: microsoft.public.dotnet.framework.aspnet
> NNTP-Posting-Host: adsl-065-083-137-202.sip.asm.bellsouth.net
65.83.137.202
> Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
> Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:158558
> X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
> Hi,
> I need to display a DateTime field in 'mm/dd/yyyy' in a DataGrid.. On
> myGrid1 - Properties - Columns - myColumn1 - Text format string:
> I tried to put 'mm/dd/yyyy' in there and it displays 'mm/dd/yyyy' in stead
> of '04/10/2001'. I know I didn't do it right. Please let me know what's
the
> correct way to display a 'mm/dd/yyyy' format for a DateTime coulmn.
> Thanks.
> Eddy
Thanks Brian, Charlie,
When applying that format, it displays 00/09/1999 instead of 07/09/1999. I
will look at the http://asp.net/ and DataGrid Property Builder dialog box.
Eddy
"Charlie Nilsson [MSFT]" <CharlieNilsson_CUTOUT_@.hotmail.com> wrote in
message news:N6MXH28RDHA.1616@.cpmsftngxa06.phx.gbl...
> Vincent,
> Try using the format "{0:MM/dd/yyyy}". Also, check the Help section
within
> the DataGrid Property Builder dialog box. It will provide you with more
> information about the format modifiers.
> Charlie Nilsson [msft]
> Visual Studio Update
> --
> This posting is provided "AS IS" with no warranties, and confers no
rights.
> Use of included script samples are subject to the terms specified at
> http://www.microsoft.com/info/cpyright.htm
> Note: For the benefit of the community-at-large, all responses to this
> message are best directed to the newsgroup/thread from which they
> originated.
> -------
> > From: "Eddy Soeparmin" <esoeparmin@.clientprofiles.com>
> > Subject: Text Format String - Please help
> > Date: Fri, 11 Jul 2003 11:03:09 -0400
> > Lines: 14
> > X-Priority: 3
> > X-MSMail-Priority: Normal
> > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
> > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
> > Message-ID: <udPQR07RDHA.2008@.TK2MSFTNGP11.phx.gbl>
> > Newsgroups: microsoft.public.dotnet.framework.aspnet
> > NNTP-Posting-Host: adsl-065-083-137-202.sip.asm.bellsouth.net
> 65.83.137.202
> > Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
> > Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.aspnet:158558
> > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
> > Hi,
> > I need to display a DateTime field in 'mm/dd/yyyy' in a DataGrid.. On
> > myGrid1 - Properties - Columns - myColumn1 - Text format string:
> > I tried to put 'mm/dd/yyyy' in there and it displays 'mm/dd/yyyy' in
stead
> > of '04/10/2001'. I know I didn't do it right. Please let me know what's
> the
> > correct way to display a 'mm/dd/yyyy' format for a DateTime coulmn.
> > Thanks.
> > Eddy
Hi Brian,
I finally get it to work now. Earlier I got 00/09/1999 instead of 07/09/1999
because I'm using {0:mm/dd/yyyy}. It's case sensitive, and it must be
{0:MM/dd/yyyy}.
Thanks.
Eddy
"Brian Smith" <smitho@.mantech-wva.com> wrote in message
news:074e01c347cc$f65bfcf0$a001280a@.phx.gbl...
> Eddy,
> I found myself having this problem the other day and
> couldn't find any documentation in the MSDN other than for
> numbers. Here is what you need to put in the format
> string:
> {0:mm/dd/yyyy}
> Also,
> http://asp.net/ is a really good site for anything related
> to ASP .NET or .NET in general. The people in the Forums
> there are very helpful and usually can answer my questions
> within an hour.
>
> >--Original Message--
> >Hi,
> >I need to display a DateTime field in 'mm/dd/yyyy' in a
> DataGrid.. On
> >myGrid1 - Properties - Columns - myColumn1 - Text format
> string:
> >I tried to put 'mm/dd/yyyy' in there and it
> displays 'mm/dd/yyyy' in stead
> >of '04/10/2001'. I know I didn't do it right. Please let
> me know what's the
> >correct way to display a 'mm/dd/yyyy' format for a
> DateTime coulmn.
> >Thanks.
> >Eddy
> >.
"Eddy Soeparmin" <esoeparmin@.clientprofiles.com> wrote in message news:<udPQR07RDHA.2008@.TK2MSFTNGP11.phx.gbl>...
> Hi,
> I need to display a DateTime field in 'mm/dd/yyyy' in a DataGrid.. On
> myGrid1 - Properties - Columns - myColumn1 - Text format string:
> I tried to put 'mm/dd/yyyy' in there and it displays 'mm/dd/yyyy' in stead
> of '04/10/2001'. I know I didn't do it right. Please let me know what's the
> correct way to display a 'mm/dd/yyyy' format for a DateTime coulmn.
> Thanks.
> Eddy
try {0:d} in the datafomatstring property
John
Text Format for Decimal
AmountL.Text comes up as 9999999.99 and I want to format this so it is
displayed as 9,999,999.99. Can someone help me with this simple task?
AmountL.Text = dr.Item("Amount")
Thanks!
PhilOn Oct 8, 8:35 pm, "pvong" <phillip*at*yahoo*dot*comwrote:
Quote:
Originally Posted by
I'm grabbing "Amount" from a DB with Decimal format. The outpul of
AmountL.Text comes up as 9999999.99 and I want to format this so it is
displayed as 9,999,999.99. Can someone help me with this simple task?
>
AmountL.Text = dr.Item("Amount")
Hi Phil
try to format String.Format("{0:0,0}", dr.Item("Amount"));
"pvong" <phillip*at*yahoo*dot*comwrote in message
news:ettLZmdCIHA.4176@.TK2MSFTNGP06.phx.gbl...
Quote:
Originally Posted by
I'm grabbing "Amount" from a DB with Decimal format. The outpul of
AmountL.Text comes up as 9999999.99 and I want to format this so it is
displayed as 9,999,999.99. Can someone help me with this simple task?
>
AmountL.Text = dr.Item("Amount")
AmountL.Text = dr.Item("Amount").ToString("#,##0.00")
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Mark,
I'm getting this error message.
Input string was not in a correct format.
I'm trying to do this in VB.Net
"Mark Rae [MVP]" <mark@.markNOSPAMrae.netwrote in message
news:uRjwv5dCIHA.5600@.TK2MSFTNGP04.phx.gbl...
Quote:
Originally Posted by
"pvong" <phillip*at*yahoo*dot*comwrote in message
news:ettLZmdCIHA.4176@.TK2MSFTNGP06.phx.gbl...
>
Quote:
Originally Posted by
>I'm grabbing "Amount" from a DB with Decimal format. The outpul of
>AmountL.Text comes up as 9999999.99 and I want to format this so it is
>displayed as 9,999,999.99. Can someone help me with this simple task?
>>
>AmountL.Text = dr.Item("Amount")
>
AmountL.Text = dr.Item("Amount").ToString("#,##0.00")
>
>
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
This is almost perfect. It cuts off my pennies. How do I get it to include
the 2 digits after the decimal?
"Alexey Smirnov" <alexey.smirnov@.gmail.comwrote in message
news:1191870335.161972.326090@.k79g2000hse.googlegr oups.com...
Quote:
Originally Posted by
On Oct 8, 8:35 pm, "pvong" <phillip*at*yahoo*dot*comwrote:
Quote:
Originally Posted by
>I'm grabbing "Amount" from a DB with Decimal format. The outpul of
>AmountL.Text comes up as 9999999.99 and I want to format this so it is
>displayed as 9,999,999.99. Can someone help me with this simple task?
>>
>AmountL.Text = dr.Item("Amount")
>
Hi Phil
>
try to format String.Format("{0:0,0}", dr.Item("Amount"));
>
>
On Oct 8, 9:27 pm, "pvong" <phillip*at*yahoo*dot*comwrote:
Quote:
Originally Posted by
This is almost perfect. It cuts off my pennies. How do I get it to include
the 2 digits after the decimal?
>
"Alexey Smirnov" <alexey.smir...@.gmail.comwrote in message
>
news:1191870335.161972.326090@.k79g2000hse.googlegr oups.com...
>
>
>
Quote:
Originally Posted by
On Oct 8, 8:35 pm, "pvong" <phillip*at*yahoo*dot*comwrote:
Quote:
Originally Posted by
I'm grabbing "Amount" from a DB with Decimal format. The outpul of
AmountL.Text comes up as 9999999.99 and I want to format this so it is
displayed as 9,999,999.99. Can someone help me with this simple task?
>
Quote:
Originally Posted by
Quote:
Originally Posted by
AmountL.Text = dr.Item("Amount")
>
Quote:
Originally Posted by
Hi Phil
>
Quote:
Originally Posted by
try to format String.Format("{0:0,0}", dr.Item("Amount"));- Hide quoted text -
>
- Show quoted text -
{0:0,0.00}
"pvong" <phillip*at*yahoo*dot*comwrote in message
news:eGbLO$dCIHA.464@.TK2MSFTNGP02.phx.gbl...
[top-posting corrected]
Quote:
Originally Posted by
"Mark Rae [MVP]" <mark@.markNOSPAMrae.netwrote in message
news:uRjwv5dCIHA.5600@.TK2MSFTNGP04.phx.gbl...
Quote:
Originally Posted by
>"pvong" <phillip*at*yahoo*dot*comwrote in message
>news:ettLZmdCIHA.4176@.TK2MSFTNGP06.phx.gbl...
>>
Quote:
Originally Posted by
>>I'm grabbing "Amount" from a DB with Decimal format. The outpul of
>>AmountL.Text comes up as 9999999.99 and I want to format this so it is
>>displayed as 9,999,999.99. Can someone help me with this simple task?
>>>
>>AmountL.Text = dr.Item("Amount")
>>
>AmountL.Text = dr.Item("Amount").ToString("#,##0.00")
Quote:
Originally Posted by
I'm getting this error message.
Input string was not in a correct format.
I'm trying to do this in VB.Net
AmountL.Text = Convert.ToDecimal(dr.Item("Amount")).ToString("#,##0.00")
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
PERFECT!!!!
Thanks!
Phil
"Alexey Smirnov" <alexey.smirnov@.gmail.comwrote in message
news:1191871744.302099.71660@.22g2000hsm.googlegrou ps.com...
Quote:
Originally Posted by
On Oct 8, 9:27 pm, "pvong" <phillip*at*yahoo*dot*comwrote:
Quote:
Originally Posted by
>This is almost perfect. It cuts off my pennies. How do I get it to
>include
>the 2 digits after the decimal?
>>
>"Alexey Smirnov" <alexey.smir...@.gmail.comwrote in message
>>
>news:1191870335.161972.326090@.k79g2000hse.googlegr oups.com...
>>
>>
>>
Quote:
Originally Posted by
On Oct 8, 8:35 pm, "pvong" <phillip*at*yahoo*dot*comwrote:
>I'm grabbing "Amount" from a DB with Decimal format. The outpul of
>AmountL.Text comes up as 9999999.99 and I want to format this so it is
>displayed as 9,999,999.99. Can someone help me with this simple task?
>>
Quote:
Originally Posted by
>AmountL.Text = dr.Item("Amount")
>>
Quote:
Originally Posted by
Hi Phil
>>
Quote:
Originally Posted by
try to format String.Format("{0:0,0}", dr.Item("Amount"));- Hide quoted
text -
>>
>- Show quoted text -
>
{0:0,0.00}
>
Perfect! Thanks!
"Mark Rae [MVP]" <mark@.markNOSPAMrae.netwrote in message
news:urfl%23EeCIHA.1188@.TK2MSFTNGP04.phx.gbl...
Quote:
Originally Posted by
"pvong" <phillip*at*yahoo*dot*comwrote in message
news:eGbLO$dCIHA.464@.TK2MSFTNGP02.phx.gbl...
>
[top-posting corrected]
>
Quote:
Originally Posted by
>"Mark Rae [MVP]" <mark@.markNOSPAMrae.netwrote in message
>news:uRjwv5dCIHA.5600@.TK2MSFTNGP04.phx.gbl...
Quote:
Originally Posted by
>>"pvong" <phillip*at*yahoo*dot*comwrote in message
>>news:ettLZmdCIHA.4176@.TK2MSFTNGP06.phx.gbl...
>>>
>>>I'm grabbing "Amount" from a DB with Decimal format. The outpul of
>>>AmountL.Text comes up as 9999999.99 and I want to format this so it is
>>>displayed as 9,999,999.99. Can someone help me with this simple task?
>>
>>>AmountL.Text = dr.Item("Amount")
>>>
>>AmountL.Text = dr.Item("Amount").ToString("#,##0.00")
>
Quote:
Originally Posted by
>I'm getting this error message.
>Input string was not in a correct format.
>I'm trying to do this in VB.Net
>
AmountL.Text = Convert.ToDecimal(dr.Item("Amount")).ToString("#,##0.00")
>
>
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
text formatting?
I know this is probably very complicated but I was wondering if anyone knows where or what I should start reading to be able to do something like this? Any points or ideas would be greatly appreciated! Thanks in advance!
RayMaybe the easiest way would be to put tags into the text, and store the text as HTML within the server. Then, when you pull it out, just make sure you display it as HTML and not just text. This would mean that you would have to manually style the text and type all the tags before storing it into the server.
HTH
Jags
yeah thats what I've been doing right now, it works but I thought there might be a better way. Thanks.
Saturday, March 24, 2012
Text Masking
String formatting in C# (http://www.stevex.org/CS/blogs/dottext/articles/158.aspx) -> C# article but still applies to VB.NET. It even has an example for phone numbers!
HTH
DJ
Thanks, that helps on the output. Still looking for thoughts on Input Masking as well. I've converting an old Access App to a SQL/ASP.NET app, and alot of the fields were masked to a certain input. I can do regular expression validators, but what a hassle to right them for every input and even then it doesn't seem as intuitive.
Could you give some more details of what you are doing - I don't understand why the above wouldn't work for the situation you describe. Perhaps I've misunderstood.
DJ
No, that will work great for when I output from the database. I'm just trying to figure out a way to mask data on input. For example, in this Access app I am converting to ASP.NET, for a phone number, it has an text field that looks something like: (___) ___-____ , where it restricts (masks) input.
Your best bet is to use javascript. I don't know if you are good with JS or not, but I am sure you could find sample code for formatting a phone number using it.
I recommend this because it will be 100% client side formatting, and won't be a drag on your webserver. If you were to make the input box run at the server, and put code in its textchanged event, each time they type a number in the box it would post back to your webserver. Javascript will simply do everything client side. it would be the onchange event of the input tag that you would want to perform the formatting. Basically you look at the entered string, get all the numbers in it, and if the numbers length is 10, then you have potentially a valid phone number and should format it, otherwise do not.
Tuesday, March 13, 2012
TextBox (v2.0)
Is it possible to have a textbox always display a particular format, my
client wishes to have the textbox always display the text in this format -
0,000.00.
Is there anyway of achieving this?
Thanks
KevPlease see my answer to this same question you posted on the webcontrols
newsgroup.
-- Peter Blum
www.PeterBlum.com
Email: PLBlum@.PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
"Mantorok" <none@.tiscali.co.uk> wrote in message
news:da3g4o$6so$1@.newsfeed.th.ifl.net...
> ASP.Net 2.0 question.
> Is it possible to have a textbox always display a particular format, my
> client wishes to have the textbox always display the text in this format -
> 0,000.00.
> Is there anyway of achieving this?
> Thanks
> Kev