Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dates...

Status
Not open for further replies.

Lourry

Technical User
Jul 25, 2003
84
CA
Hello,

I would like to create a date in the following format

6/15/2004 07:20:32PM

can I do that with Date() function?

Thanks in advance!
 
Something like this ?
Format(Date(), "m/d/yyyy hh:nn:ssAM/PM")
Or this:
Format(Date(), "m/dd/yyyy hh:nn:ssAM/PM")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
like PHV said, but even simpler is Now(). That is if you want the CURRENT date & time. Date() alone will give you
"6/15/2004" ,current also.
Otherwise, like PHV said.
Good Luck!
 
Oops, good point dboulos.
Date() always returns time as 12:00:00AM ...
 
Hi

I Have a start date and a completion date held in a table and I need to be able to show how many days a project is over-running in another text box.

Any ideas how I might acheive this?

Thank you in advance
 
topgeek (I always wondered who the top on is - )

You should start a new thread...

But if you just need the number of calendar days between two dates, use:
Code:
Int(completiondate - startdate)



HTH,
Bob [morning]
 
Lourry et al,

Dates are just NUMBERS like today is 38154. It is the number of days from 1/1/1900.

What you requested is a Date Format which is DISPLAY TEXT. You can format Year, Month & Day in any number of combinations of numeric or text values like 6/16/2006 {Format(Date, "m/d/yyyy")} or Wed, June 06, '04 {Format(Date, "ddd, mmmm, dd, 'yy")}

:)


Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks for the replies!

It works perfectly...
I just used the following:

Format(Now(), "m/d/yyyy hh:nn:ssAM/PM")
 
Sorry Lourry, my post was very brief & not too explicit.
Now() alone, will format it as you requested, automatically.
You don't need the Format() function. ...just for the record... But obviously, it still works. & good to know in general.

topgeek, you can use the DateDiff() function.
it takes 3 obligatory arguments.
DateDiff("m",date1,date2)
1st argument returns the type of value you want returned.
How many months "m" separate the 2 dates, or how many seconds "s", or days "d".
The 2nd argument is, usually, the earlier of the dates (start time), 3rd argument the later date. If reversed, you'll get a negative return.

Good luck to both!
 
Thanks Skip for the reply!

dboulos: Thanks! I'll keep that in mind. Actually, your answer to topgeek is very useful to me as well since my next step is to find the difference in seconds between two dates. I guess I should also thank topgeek for posting in this thread : )
 
Hello again,

I tried to set a date to a variable by:

Code:
Const date1 As Date = "1/1/1950 12:00:00AM"

but it only stores 1/1/1950 in the variable, it doesn't store the time! How can I declare it so that it includes the time?

Thanks again! : )
 
In Access dates are identified with # signs.

Code:
Const date1 As Date = "#1/1/1950 12:00:00AM#"


HTH,
Bob [morning]
 
Const date1 As Date = "1/1/1950 12:00:00AM"

With the above, if you cast date1 to a double it will show the days since 1/1/1900 in the integer part and 0 in the time part because 12:00:00AM is 0 time. Try putting 12:02:00 in the time part and you will see a value.
 
Thanks for the reply!!

It works fine now! : )

Thanks again!
 
Hello all, I just wanted to ask another date question to this post. I want to retrieve the current month and year but I am trying to get it like this 04/04. this is how I am doing it in a DTS:

Dim CurDate
CurDate = Month(date)&"/"&year(date)

What I get is something like this 7/2004

How can I format this differently?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top