Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 409
  • Last Modified:

Format Excell Cell date

Hello,
can you please help,
I use a code to get information form SQL to Excel.
one of the lines in the code is
"WHERE((OrderDate >= '" & sh.[u1] & "')  And (OrderDate <='" & sh.[v1] & "')) "

if I format the cells like this, my Code works
Range("u1").Select
ActiveCell.FormulaR1C1 = "=TODAY()-1 + ""00:00:00"""
Range("u1").Select
ActiveCell.FormulaR1C1 = "=TODAY()-1 +""23:59:59"""


the issue I have is I need to be able to change the date in the cell.
so if I format the cells to below, my code will not work.

Range("u1").Select
Selection.NumberFormat = "[$-409]mm/dd/yyyy ""00:00:00"""
Range("u1").Select
Selection.NumberFormat = "[$-409]mm/dd/yyyy ""23:59:59"""

can you please help,
thanks
0
W.E.B
Asked:
W.E.B
  • 2
1 Solution
 
mvidasCommented:
How about using the format function when pulling the date from excel?

"WHERE((OrderDate >= '" & Format(sh.[u1], "mm/dd/yyyy hh:mm:ss") & "')  And (OrderDate <='" & Format(sh.[v1], "mm/dd/yyyy hh:mm:ss") & "')) "

Matt
0
 
W.E.BAuthor Commented:
thanks Matt,
this worked.

((OrderDate >= '" & format(sh.[u1], "mm/dd/yyyy 00:00:00") & "')  And (OrderDate <='" & format(sh.[v1], "mm/dd/yyyy 23:59:59") & "'))
0
 
W.E.BAuthor Commented:
Thank you.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now