Combining Text and Date function in VBA

P

Pablo

Here is a piece of my code. It will not compile.
I want SDate to be a text string in the format of "8/10/06 00:00:00 AM"
and EDate "8/10/06 11:59:59 PM". I preffered if this values were
yesterday's dates, but they have to change daily. Any suggestions?
Thanks.

My Code:

Dim SDate As String
Dim EDate As String

Set SDate = "TEXT(Month(TODAY())&" / "&DAY(TODAY())&" / "&Year(today())
& ""00:00:00 AM"""
Set SDate = "TEXT(Month(TODAY())&" / "&DAY(TODAY())&" / "&Year(today())
& ""11:59:59 PM"""
 
R

Ron Rosenfeld

Here is a piece of my code. It will not compile.
I want SDate to be a text string in the format of "8/10/06 00:00:00 AM"
and EDate "8/10/06 11:59:59 PM". I preffered if this values were
yesterday's dates, but they have to change daily. Any suggestions?
Thanks.

My Code:

Dim SDate As String
Dim EDate As String

Set SDate = "TEXT(Month(TODAY())&" / "&DAY(TODAY())&" / "&Year(today())
& ""00:00:00 AM"""
Set SDate = "TEXT(Month(TODAY())&" / "&DAY(TODAY())&" / "&Year(today())
& ""11:59:59 PM"""

Not sure what you want to do with these, but you need to have a triple
double-quote before the time section in order to compile.

e.g. """00:00:00 AM"""


--ron
 
P

Pablo

I added the quotation mark and still doesn't compile.
I am using this to querry a database that is online. I am trying to
populate some fields so I can automate the generation of a daily
report.

I tried this variant but still does not work...Thanks for your help.

Dim SDate As String
Dim EDate As String

Set SDate = "TEXT(Month(TODAY(),mm)&" / "&DAY(TODAY(),dd)&" /
"&Year(today(),yy) & """"00:00:00 AM"""
Set SDate = "TEXT(Month(TODAY(),mm)&" / "&DAY(TODAY(),dd)&" /
"&Year(today(),yy) & """"11:59:59 PM"""
 
R

Ron Rosenfeld

I added the quotation mark and still doesn't compile.
I am using this to querry a database that is online. I am trying to
populate some fields so I can automate the generation of a daily
report.

I tried this variant but still does not work...Thanks for your help.

Dim SDate As String
Dim EDate As String

Set SDate = "TEXT(Month(TODAY(),mm)&" / "&DAY(TODAY(),dd)&" /
"&Year(today(),yy) & """"00:00:00 AM"""
Set SDate = "TEXT(Month(TODAY(),mm)&" / "&DAY(TODAY(),dd)&" /
"&Year(today(),yy) & """"11:59:59 PM"""

Now you have 4 double quotes. Proper syntax is for three.

What do you mean by "does not work"?
--ron
 
P

Pablo

I found a way to work around it. I put the text I wanted into a cell
and them asigned the cellvalue to the variable. THANKS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top