CodeVerge.Net Beta


   Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > Asp.Net Forum > visual_studio.visual_studio_2005 Tags:
Item Type: Date Entered: 2/15/2007 7:44:48 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 3 Views: 33 Favorited: 0 Favorite
4 Items, 1 Pages 1 |< << Go >> >|
"NissanSE98" <>
NewsGroup User
Date data Type SQL Database2/15/2007 7:44:48 PM

0

 

 I have an entry where I need to enter a date (MM/DD/YYYY). I have a validator to make sure the date is entered correctly. The SQL data type is smalldatetime which adds a time to the date. If I enter "2/15/2007" into the entry, the data that is saved it "2/15/2007 12:00:00 AM." Which, I read through the forums to see that there's no easy way to fix that so I was just going to allow it to happen (I dont want it there). On my gridview, where I view all the entered data, I put a comparevalidator to validate the entry to make sure the date is in the correct format. This is where the kicker is. The validator wont allow the update if the entry has a time. Therefore, if I have to update, I have to erase the time portion of the entry. If I have an entry "2/15/2007 12:00:00 AM " and hit update, then I have to erase the "12:00:00 AM" portion of the entry before the update is allowed.

Is there a way to get rid of the time portion of the entry for good?

How do I fix the validator to validate "2/15/2007 12:00:00 AM"  or "2/15/2007"?

 

 

"ask_Scotty" <>
NewsGroup User
Re: Date data Type SQL Database2/15/2007 10:12:34 PM

0

Hello my friend,

Do the following on your date on the web page: -

<%# Container.DataItem("YourDateField").ToString("DD/MM/yyyy") %>

This should get rid of the time part of the date. 

Kind regards

Scotty

 

"rojay12" <>
NewsGroup User
Re: Date data Type SQL Database2/15/2007 10:16:01 PM

0

I am curious to find out if anyone knows the answer to this.  I can never get it to store correctly.  I have always been told to format it when you bind it in your datagrid or gridview.

 

<asp:Textbox runat="server" id="txtDate" Text='<%# Bind("dtDateOnlyField", "{0:M/dd/yyyy}") %>' />

or i think this works too

<asp:Textbox runat="server" id="txtDate" Text='<%# Bind("dtDateOnlyField", "{0:d}") %>' />


Jared Roberts
Lead Application Developer
"rojay12" <>
NewsGroup User
Re: Date data Type SQL Database2/15/2007 10:18:55 PM

0

FYI here is a good page with a bunch of String.Format formats.

http://idunno.org/archive/2004/14/01/122.aspx


Jared Roberts
Lead Application Developer
4 Items, 1 Pages 1 |< << Go >> >|




   
  Privacy | Contact Us
All Times Are GMT