0

I'm having a problem with a MySQL query for returning the "last visit" field in a table.

Originally I had:

select fname, lname, last_visit from patient where isactive = 1 and uid = 1

Which worked perfectly in MySQL, but as soon as the query is executed by my ASP.NET app, it adds in the time field also to the date area. So 2011-12-12 becomes 12/12/2011 12:00:00 AM

I tried this also, with no improvement:

select fname, lname, DATE(last_visit) as last_visit from patient where isactive = 1 and uid = 1 order by lname

How can I fix this?

2
  • Are you storing this date in a DateTime object? Commented Mar 13, 2012 at 19:26
  • I mean in VB.net, what data type is it being stored into? Commented Mar 13, 2012 at 19:31

2 Answers 2

2

A .NET DateTime object always has a Time component. In your app, you can just ignore it though.

Dim myDate As New DateTime(2011,12,12)

Dim dateAndTime As String = myDate.ToString() 'Prints 12/12/2011 12:00:00 AM

Dim onlyDate As String = myDate.ToShortDateString() 'Prints 12/12/2011
Sign up to request clarification or add additional context in comments.

Comments

0

MySql will add the time by default if its a datetime field. Try implementing a custom date and time format string. MSDN article about custom date/time formats

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.