|
List Info
Thread: c# .net date formatting question
|
|
| c# .net date formatting question |
  United States |
2007-07-26 06:59:15 |
I have a smalldatetime column coming from a SQL server
database in a
dataset. I want to format it as the date portion only for a
text box.
I can format the whole thing using the following command
this.txtDateOfBirth.Text =
dsPersonAttrib.Tables["PersonAttributes"].Rows[0]
["DateOfBirth"].ToString();
but if I try to format with ToString("MM/dd/yyyy")
it won't compile
saying that the ToString function only accepts one
parameter. Is the
data type coming from the database one that the formatting
function
doesn't recognize.
I can't use the date portion of the string because it does
not contain
leading zeros. ex 7/7/2007. This looks sloppy and doesn't
allow the
user to modify the date to 11/22/2007 without shifting the
text.
How do I do this???
Czeb
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "DotNetDevelopment, VB.NET, C# .NET,
ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting"
group.
To post to this group, send email to DotNetDevelopment googlegroups.com
To unsubscribe from this group, send email to
DotNetDevelopment-unsubscribe googlegroups.com
For more options, visit this group at
http:
//cm.megasolutions.net/forums/default.aspx
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: c# .net date formatting question |

|
2007-07-26 10:09:19 |
Here you go;
http://www.geekzilla.co.uk/View00FF7904-B
510-468C-A2C8-F859AA20581F.htm
On 26/07/07, Czeb <james.czebiniak pearlcarroll.com>
wrote:
>
> I have a smalldatetime column coming from a SQL server
database in a
> dataset. I want to format it as the date portion only
for a text box.
>
> I can format the whole thing using the following
command
> this.txtDateOfBirth.Text =
>
dsPersonAttrib.Tables["PersonAttributes"].Rows[0]
> ["DateOfBirth"].ToString();
>
> but if I try to format with
ToString("MM/dd/yyyy") it won't compile
> saying that the ToString function only accepts one
parameter. Is the
> data type coming from the database one that the
formatting function
> doesn't recognize.
>
> I can't use the date portion of the string because it
does not contain
> leading zeros. ex 7/7/2007. This looks sloppy and
doesn't allow the
> user to modify the date to 11/22/2007 without shifting
the text.
> How do I do this???
>
> Czeb
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "DotNetDevelopment, VB.NET, C# .NET,
ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting"
group.
To post to this group, send email to DotNetDevelopment googlegroups.com
To unsubscribe from this group, send email to
DotNetDevelopment-unsubscribe googlegroups.com
For more options, visit this group at
http:
//cm.megasolutions.net/forums/default.aspx
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: c# .net date formatting question |

|
2007-07-26 10:35:22 |
Scripsit Czeb:
> Is the data type coming from the database one that the
formatting
function doesn't recognize?
Hmm...well, as long as the dataset has it defined as
System.DateTime,
you should be able to do it. Try it in multiple steps:
using System;
using System.Globalization;
DateTime dob
=
dsPersonAttrib.Tables["PersonAttributes"].Rows[0][
"DateOfBirth"];
this.txtDateOfBirth.Text
= dob.ToString("d"
DateTimeFormatInfo.InvariantInfo);
"d" should give you the date, with leading zeros.
If you get an error on the assignment, then you're not
getting back
something that's a DateTime, so you'll need to do something
like:
DateTime dob
= Convert.ToDateTime(
dsPersonAttrib.Tables["PersonAttributes"].Rows[0][
"DateOfBirth"]
);
All done without the aid of the IDE, so let
(Intelli)sensibility be your
guide. Good
luck!
-- Peter Smith
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "DotNetDevelopment, VB.NET, C# .NET,
ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting"
group.
To post to this group, send email to DotNetDevelopment googlegroups.com
To unsubscribe from this group, send email to
DotNetDevelopment-unsubscribe googlegroups.com
For more options, visit this group at
http:
//cm.megasolutions.net/forums/default.aspx
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: c# .net date formatting question |
  United States |
2007-07-26 10:36:47 |
Unfortunately, the date field is coming from a database
dataset and
the c# compiler won't accept the formatting in the
ToString()
function.
As an attempt to get this to work I did the following in the
sql
statement
left('0' + rtrim(month(EffectiveDate)),2) + '/' + left('0'
+
rtrim(day(EffectiveDate)),2) + '/' +
rtrim(year(EffectiveDate)) as
EffectiveDate
This does properly format the date into the dataset and look
good in
the text box.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "DotNetDevelopment, VB.NET, C# .NET,
ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting"
group.
To post to this group, send email to DotNetDevelopment googlegroups.com
To unsubscribe from this group, send email to
DotNetDevelopment-unsubscribe googlegroups.com
For more options, visit this group at
http:
//cm.megasolutions.net/forums/default.aspx
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: c# .net date formatting question |
  United States |
2007-07-27 01:28:29 |
The compiles is recognizing the value as a string and not a
date. You
can not call string.ToString("MM/dd/yyyy"). This
overload is only
valid with the Date Type.
Additionally, You should be able to see this as Visual
Studio's
Intellisense does not offer overloads for a string.ToString
This works for me.
this.txtDateOfBirth.Text
=Date.Parse("(dsPersonAttrib.Tables["PersonAttribu
tes"].Rows[0]
["DateOfBirth"]).ToString("MM/dd/yyyy")
Alex Higgins
http://www.alexanderh
iggins.com
On Jul 26, 11:36 am, Czeb <james.czebin... pearlcarroll.com> wrote:
> Unfortunately, the date field is coming from a database
dataset and
> the c# compiler won't accept the formatting in the
ToString()
> function.
>
> As an attempt to get this to work I did the following
in the sql
> statement
> left('0' + rtrim(month(EffectiveDate)),2) + '/' +
left('0' +
> rtrim(day(EffectiveDate)),2) + '/' +
rtrim(year(EffectiveDate)) as
> EffectiveDate
>
> This does properly format the date into the dataset and
look good in
> the text box.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "DotNetDevelopment, VB.NET, C# .NET,
ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting"
group.
To post to this group, send email to DotNetDevelopment googlegroups.com
To unsubscribe from this group, send email to
DotNetDevelopment-unsubscribe googlegroups.com
For more options, visit this group at
http:
//cm.megasolutions.net/forums/default.aspx
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: c# .net date formatting question |
  United States |
2007-07-27 06:43:00 |
Thanks for all of the help guys!!!.
Czeb
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "DotNetDevelopment, VB.NET, C# .NET,
ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting"
group.
To post to this group, send email to DotNetDevelopment googlegroups.com
To unsubscribe from this group, send email to
DotNetDevelopment-unsubscribe googlegroups.com
For more options, visit this group at
http:
//cm.megasolutions.net/forums/default.aspx
-~----------~----~----~----~------~----~------~--~---
|
|
[1-6]
|
|