1

When I looked at the database record, the datetime saves like this: 4/6/2012 04:42:28 PM

because I've save it using dbtype.string

Now, I'm getting the date only, not including time, this is my code:

    Private Sub getpapererror(ByVal ddate As String)
    Dim sqlstr As String = "select * from perror where date(ddate) = $xddate"
    Dim sqlcmd As New SQLiteCommand(sqlstr, mycon)
    sqlcmd.Parameters.Add("$xddate", DbType.String).Value = ddate
    ...
    End Sub

    Dim xdt As DateTime = DateTime.Now
    getpapererror("#" & xdt.Month.ToString & "/" & xdt.Day.ToString & "/" & xdt.Year.ToString & "#")

I want to get only the date

1
  • 1
    You say you're getting the date, and that you only want to get the date - it's not clear what's wrong... (although you should be using string.Format if you really want to use strings). Why aren't you just using a date/time type anyway? Commented Apr 4, 2012 at 11:00

1 Answer 1

2

If you want to get a date value as a string with certain format (like "4/6/2012"), you could look into sqlite's strftime().

If you must save strings, maybe you can mangle the string afterwards. In python I'd try something like

>>> ds = "4/6/2012 5:55:55 PM"
>>> dt, tm = ds.split(None, 1)
>>> dt
'4/6/2012'
>>> tm
'5:55:55 PM'
Sign up to request clarification or add additional context in comments.

3 Comments

@Jon Skeet, yes I want to use dbtype.string because it displays the exact date and time, not like using dbtype.DateTime it displays like this: 2012-04-06 18:57:26.015625, the time was not properly managed
@XenKid As said, strftime will make most any kind of output from a real date type.
Yes, I've used strftime, but it does get what I want: here's some of my code: Dim ss As String = "select dcash from paidpend where strftime('%m-%d-%Y', dtime) = $xddate", But that can't get when saved to dbtype.String

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.