Re: Date extraction
- From: "Tony Proctor" <tony_proctor@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 30 May 2007 10:09:37 +0100
I don't know which database you're using, and whether you're reading these
fields as text values or real Date values
Assuming, for now, that you're reading these dates as text strings then the
first problem is a lot easier than you think. VB understands that date
format because it's part of the ISO 8601 standard. For instance:
Private Sub Form_Load()
Dim sDateString As String
Dim dDateTimeValue As Date
Dim dDateValue
sDateString = "2007-05-30 01:55:35"
' Show that we can easily decode this string to a date/time value
dDateTimeValue = CDate(sDateString)
MsgBox "Date/time value is " & CStr(dDateTimeValue)
' Now just show how to extra the date portion
dDateValue = DateValue(CDate(sDateString))
MsgBox "Date value is " & CStr(dDateValue)
End Sub
You can then use your Date variables (not String variables) such as
dDateValue in real comparison tests like:
If dDateValue >= CDate("2007-05-28") And dDateValue <
CDate("2007-05-31") Then
In your second question, did you mean a VB query or a SQL query?
Tony Proctor
"Luiz Horacio" <lhoracio@xxxxxxxxx> wrote in message
news:%23MIACjnoHHA.3264@xxxxxxxxxxxxxxxxxxxxxxx
Hi,database.
One (in fact two) stupid questions. I have a date/time field in a
Data is, of course, saved as '2007-05-30 01:55:35' format. I have someit.
queries that include this field, and can't find a clean way to work with
rst_anything(1)
1. How can I extract date part of this field, so that I can get only
'2007-05-30' so that I can make var_AdmDate in var_AdmDate =
return '2007-05-30' instead of '2007-05-30 01:55:35' ?and
2. Can I work with date part so a query like "... Where AdmDate between
'2007-05-28' and '2007-05-30' And..." will work without the need to add
hours and minutes (like "... Where AdmDate between '2007-05-28 00:00:00'
'2007-05-30 23:59:59' And...")?but
I tried a lot of things, ended up with ...left(value,10) for question #1
this looks stupid to me. In the same way, on question #2 I ended up with
"... Where AdmDate between '2007-05-28 00:00:00' and '2007-05-30 23:59:59'
And..." , adding hours:min:sec in code, but this looks stupid too...
Thanks,
Luiz Horacio
.
- References:
- Date extraction
- From: Luiz Horacio
- Date extraction
- Prev by Date: Re: Date extraction
- Next by Date: Re: resource template?
- Previous by thread: Re: Date extraction
- Next by thread: Re: Date extraction
- Index(es):
Relevant Pages
|