|
-
Jan 3rd, 2007, 10:06 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Date Question
I have a small question... If I want to assign a date to a date variable in the code... How do i do it...
I want the variable datDiff to be equal to 01/00/00 (mm/dd/yyyy)
What format does the date have to be in?
Hey... If you found this post helpful please rate it.

-
Jan 3rd, 2007, 10:09 PM
#2
Re: Date Question
Not sure what DateDiff and formatting have in common in your question but here we go:
VB Code:
Debug.Print Format(Now, "mm/dd/yyyy")
'both dates must be defined as Date or at least have recognizable dates format as shown above
Debug.Print DateDiff("d", Date1, Date2)
-
Jan 3rd, 2007, 10:22 PM
#3
Thread Starter
Hyperactive Member
Re: Date Question
Nooo... lol... Its datDiff not DateDiff... datDiff is a variable... and format is just like in what way can I assign a date to a date variable...
Like I want to subtract a date (01/00/0000 - mm/dd/yyyy) from the actual date to get one month less... but I don't know how to assign 01/00/0000 to a variable... so what is the standard way of putting in a date during coding...
I hope that makes it clear...
Hey... If you found this post helpful please rate it.

-
Jan 3rd, 2007, 10:23 PM
#4
Re: Date Question
You have to use # to assign:
VB Code:
Dim VarName As Date
VarName = #1/1/2000#
About your 01/00/00: day cannot be 0!
-
Jan 3rd, 2007, 10:24 PM
#5
Thread Starter
Hyperactive Member
Re: Date Question
Umm... then I need to subtract one month from a date... how would I do that???
Hey... If you found this post helpful please rate it.

-
Jan 3rd, 2007, 10:26 PM
#6
Re: Date Question
 Originally Posted by khanjan_a2k
Umm... then I need to subtract one month from a date... how would I do that???
VB Code:
Dim VarDate As Date
VarDate = DateAdd("m", -1, Date) 'Substract 1 month from current date
-
Jan 3rd, 2007, 10:28 PM
#7
Thread Starter
Hyperactive Member
Re: Date Question
Just want to make sure... so...
Is this the correct way to do it...
VB Code:
Dim datToday As Date
Dim datNew As Date
datToday = Format(Now, "mm/dd/yyyy")
datNew = DateAdd("m", -1, datToday)
Hey... If you found this post helpful please rate it.

-
Jan 3rd, 2007, 10:30 PM
#8
Re: Date Question
You don't need to use Format, a date is always a date. Format must be used just when showing a date to the user.
-
Jan 3rd, 2007, 10:34 PM
#9
Thread Starter
Hyperactive Member
Re: Date Question
Oh thanx for your help jcis... I really appreciate it
Khanjan
Hey... If you found this post helpful please rate it.

-
Jan 3rd, 2007, 10:35 PM
#10
Re: Date Question
 Originally Posted by khanjan_a2k
Nooo... lol... Its datDiff not DateDiff...
Well, that wasn't clear and in fact it appeared as it was a typo so try not to name your variables similar to those VB functions...
-
Jan 3rd, 2007, 11:28 PM
#11
Re: [RESOLVED] Date Question
I would suggest making it a habit to use DateSerial() to assign the date whenever possible rather than passing a string... If passing a string, best to pass the month as MMM so there's no accidental misinterpretation (usually swapping of day and month digits) from having a different date format in regional settings.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|