Solved

i cannot display only date : "01/01/2008",  this date is always accompanied with hours: "01/01/2008 00:00:00", how to correct?

Posted on 2008-10-07
12
271 Views
Last Modified: 2013-11-07
hello,

i have a datatable with a columns which is set as a datetime,
i've been trying to display only the date without hours, minutes and seconds,

i've try several Datetime members in order to change the display without success,
how can i get rid of the hours?
datatable:      

myDt.Columns.Add("a_date", typeof(DateTime));

html :

<td class="td_125"><%# DataBinder.Eval(Container.DataItem, "a_date") %></td>

filling the datatable:

//_aRow["a_date"]    = (container.Status.NextDateFullFill().ToShortTimeString()).Split(' ')[0]; 

_aRow["a_date"]    = ((DateTime)container.Status.NextDateFullFill()).ToShortDateString(); //.Substring(0, 10); 

                      ....

how to get rid of those chars, 

i need to filter through this column, i think i need it typed as a datatable, 

thank you for your help,

Open in new window

0
Comment
Question by:toshi_
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 5

Expert Comment

by:ccns
ID: 22664390
Hi there have a look at this link may anser your Q:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2674122&SiteID=1
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 125 total points
ID: 22664417
you should use:
_aRow["a_date"].Value    = (DateTime)container.Status.NextDateFullFill();

if you want to ensure to store only date:

_aRow["a_date"].Value    = ((DateTime)container.Status.NextDateFullFill()).Date;

the date always will be stored with time, there is no way to store just date, but the last choice will store the date with time 00:00

Further, when displaying, you can show a datetime as:

DateTime dt = ......; // from somewhere
string toShow = dt.ToShortDateString();
0
 

Author Comment

by:toshi_
ID: 22664431
it's exactly what i'm doing,
i'm casting to dateTime, then using the toshortdatestring(),

in my case this is not working, the display put the hours to 00:00:00 is all i could change with the solution
you linked me to.
......
0
 

Author Comment

by:toshi_
ID: 22664437
and that's the same i'm stack with
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22664464
ToShortDateString() cannot show 00:00:00
Maybe you have a compile refresh problem.
0
 

Author Comment

by:toshi_
ID: 22664547
indeed ToShortDateString() wouldn't display the "00:00:00"
but only if the columnType is string,  i wanted it on dateTime for sorting,  and with dateTime  for the column i always have the date with the time.

my last choice is to show only date created by numbers in order to sort the datatable correctly on date.


0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22664602
it is not easy to help you because you are not being specific.
Are you using a datagrid? a textbox binded to a datetime field?
In every case, you can have set some Format property to show just date
0
 
LVL 26

Assisted Solution

by:Anurag Thakur
Anurag Thakur earned 50 total points
ID: 22664788
try this

<td class="td_125">
         <%# Eval(Convert.ToDateTime("a_date").ToString("dd-MM-yyyy")) %>
</td>
0
 
LVL 6

Expert Comment

by:carlsiy
ID: 22665374
if its data in a datatable.. you must first decare the data type as System.DateTime
0
 

Author Comment

by:toshi_
ID: 22668460
carlsiy,  is what i did, in my datatable the column is declared as a datetime.

ragi0017,  i did not know i could do this,  but i think that the value to convert should be a string, am i right?

jaime olivares, i'm imrpoving my questioning skills, sorry for the lack of informations,  


all info:
my datatable column is declared as datetime,
i'm filling my columns with a dateTime value,
....
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22669111
it should work - may be a little tweak but try it out and if its still an issue let me know i will be happy to help out
0
 
LVL 6

Assisted Solution

by:carlsiy
carlsiy earned 75 total points
ID: 22674636
Try this, just a mini sample

            ///datatable
            DataTable dt = new DataTable();
            ///column creation
            DataColumn column;
            column = new DataColumn();
           
           
            ///This one is wrong
            ///although you can use this if the value to be passed is
            ///e.g. xx.ToShortDateString();
            //column.DataType = System.Type.GetType("System.String");
           
            ///This on is correct
            column.DataType = System.Type.GetType("System.DateTime");

            column.ColumnName = "Sample_date";
            column.ReadOnly = true;
            column.Unique = false;
            dt.Columns.Add(column);
           
            ///date value
            DateTime xx = new DateTime();
            xx= DateTime.Today;

            ///datarow passed value
            DataRow dr;
            dr = dt.NewRow();
            dr["Sample_date"] = xx.ToShortDateString();
            dt.Rows.Add(dr);

            ///binding
            dataGrid1.DataSource = dt;
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Connecting database in Xamarin? 6 52
ADO.NET ENTITY DATA MODEL 3 32
System.Speech 2 15
I need help converting a bitmap to an image in VB.Net 1 14
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now