ASP.Net date formatting issue - Chicagoland Sportbikes
Chicagoland Sportbikes
 
Geek Squad to the rescue! fucken computer crashing on you again? another porn site infected your computer? tierd of your wife seeing your anal fisting videos and want to lock her out of the external HD? get the answers you need from our local computer experts.

 
LinkBack Thread Tools Display Modes
post #1 of 5 (permalink) Old 06-09-2006, 04:00 PM Thread Starter
I break everything!
 
JonGu's Avatar
 
Join Date: Aug 2004
Location: Chicago, IL
Posts: 1,913
Location: Chicago, IL
Sportbike: SV650S, ZX6R, GSXR600
Years Riding: Since 04/2003
How you found us: Google
           
ASP.Net date formatting issue

Anyone use Visual Web Developer 2005? I'm trying to pull dates from a SQL server and it's pulling them correctly, but I can't get them to display without the time. For example, it will display "6/9/2006 00:00:00"

I set the DataFormatString to "{0:MM/dd/yyyy}" and it doesn't do shit. I know it's using the DataFormatString though because if I put in something like "test {0:MM/dd/yyyy}" it'll display all the dates as "test 6/9/2006 00:00:00"

Yes it is saved as datetime in the SQL server, I even tried casting it to datetime in the SQL query and still nothing. Can't get rid of the 00:00:00. It's driving me freaking insane!

Jon Gu
CCS AM/NESBA #276
JonGu is offline  
Sponsored Links
Advertisement
 
post #2 of 5 (permalink) Old 06-09-2006, 04:08 PM
Registered User
 
Join Date: Aug 2005
Location: Carol Stream
Posts: 201
Location: Carol Stream
Sportbike: Kawasaki ZX-9R
Years Riding: 5
How you found us: from a member
   
Quote:
Originally Posted by JonGu
Anyone use Visual Web Developer 2005? I'm trying to pull dates from a SQL server and it's pulling them correctly, but I can't get them to display without the time. For example, it will display "6/9/2006 00:00:00"

I set the DataFormatString to "{0:MM/dd/yyyy}" and it doesn't do shit. I know it's using the DataFormatString though because if I put in something like "test {0:MM/dd/yyyy}" it'll display all the dates as "test 6/9/2006 00:00:00"

Yes it is saved as datetime in the SQL server, I even tried casting it to datetime in the SQL query and still nothing. Can't get rid of the 00:00:00. It's driving me freaking insane!
Have you tried using datepart()? e.g.
select cast(datepart(month,datecolumn) as varchar(5)) + '/' + cast(datepart(day,datecolumn) as varchar(5)) + '/' + cast(datepart(year,datecolumn) as varchar(5)) from tablename

where "datecolumn" is the name of your column that has the date and "tablename" is the name of the table...
rworkman98 is offline  
post #3 of 5 (permalink) Old 06-09-2006, 05:32 PM
habitual line stepper
 
Jack's Avatar
 
Join Date: Apr 2002
Location: Wisconsin
Posts: 3,235
Location: Wisconsin
Sportbike: F4,Brutale,Warrior,DRZ
Years Riding: X
How you found us: .
           
Send a message via AIM to Jack
Is it stored in DateTime variable? If so try DateTime.ToShortDateString or if you want DateTime.ToLongDateString.
Jack is offline  
Sponsored Links
Advertisement
 
post #4 of 5 (permalink) Old 06-09-2006, 05:39 PM
habitual line stepper
 
Jack's Avatar
 
Join Date: Apr 2002
Location: Wisconsin
Posts: 3,235
Location: Wisconsin
Sportbike: F4,Brutale,Warrior,DRZ
Years Riding: X
How you found us: .
           
Send a message via AIM to Jack
If you want to use string.format you were on the right track, but the format is more terse. You can use simply d for short date format. Look at: http://msdn.microsoft.com/library/de...classtopic.asp
Jack is offline  
post #5 of 5 (permalink) Old 06-12-2006, 10:45 AM Thread Starter
I break everything!
 
JonGu's Avatar
 
Join Date: Aug 2004
Location: Chicago, IL
Posts: 1,913
Location: Chicago, IL
Sportbike: SV650S, ZX6R, GSXR600
Years Riding: Since 04/2003
How you found us: Google
           
It just wasn't applying the formatting string apparently. I put in this tag: HtmlEncode="False" and all of a sudden it started displaying correctly when I had {0:d} or {0:MM/dd/yyyy} in the dataformatstring. I dun really understand why it does this, but hey, it works :P

Jon Gu
CCS AM/NESBA #276
JonGu is offline  
Reply

Quick Reply
Message:
Options

Register Now



In order to be able to post messages on the Chicagoland Sportbikes forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.

User Name:
Password
Please enter a password for your user account. Note that passwords are case-sensitive.

Password:


Confirm Password:
Email Address
Please enter a valid email address for yourself.

Email Address:
OR

Log-in










Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page
Display Modes
Linear Mode Linear Mode



Posting Rules  
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

 
For the best viewing experience please update your browser to Google Chrome