|
-
Nov 6th, 2002, 09:52 PM
#1
Thread Starter
Lively Member
-
Nov 6th, 2002, 10:00 PM
#2
Stuck in the 80s
Difference between two dates:
VB Code:
Private Sub Form_Load()
Dim dDate As Date
dDate = "11/28/02"
MsgBox DateDiff("s", today, dDate)
End Sub
Gives you the number of seconds of difference.
-
Nov 6th, 2002, 10:05 PM
#3
Stuck in the 80s
This is a function I wrote awhile ago:
VB Code:
Public Function GetRemaining(ByVal i As Long) As String
Dim strString As String
'get number of days:
If Abs(i \ 86400) <> 0 Then
strString = Abs(i \ 86400) & " days, "
End If
i = i Mod 86400
'get number of hours:
If Abs(i \ 3600) <> 0 Then
strString = strString & Abs(i \ 3600) & " hours, "
End If
i = i Mod 3600
'get number of minutes:
If Abs(i \ 60) <> 0 Then
strString = strString & Abs(i \ 60) & " minutes "
End If
i = i Mod 60
'get number of seconds:
strString = strString & i & " seconds"
GetRemaining = strString
End Function
Just use the DateDiff() function to get the number of seconds, then pass it to the function to get a formatted string with days, minutes and seconds.
-
Nov 6th, 2002, 10:05 PM
#4
Thread Starter
Lively Member
-
Nov 6th, 2002, 10:06 PM
#5
Thread Starter
Lively Member
the time is irrelivant i just need the difference between two dates like today and 11/23/1976
-
Nov 6th, 2002, 10:13 PM
#6
Hyperactive Member
Use the DateDiff function. It doesn't need to return seconds it can return days, weeks months years and the like.
Look it up in the Help. Or type in the name, move over it and hit F1.
-
Nov 6th, 2002, 10:16 PM
#7
Stuck in the 80s
Originally posted by Supreme Cookie
the time is irrelivant i just need the difference between two dates like today and 11/23/1976
Then do this:
VB Code:
Private Sub Form_Load()
Dim dDate As Date
dDate = "11/28/02"
MsgBox DateDiff("d", Now, dDate)
End Sub
-
Nov 6th, 2002, 10:18 PM
#8
Stuck in the 80s
Originally posted by Supreme Cookie
um... i don't think you quite got what i'm trying to do. check the attached file and see what i'm trying to do. Attached is the project and frm. PLZ HELP if you can figure out the code just paste it in and post back.
No one's going to do your homework for you. We give you code, you find out how to incorporate it.
If someone reposts your code but completely working, I'm going to be horribly disappointed that they'd do such a thing.
-
Nov 6th, 2002, 10:20 PM
#9
Hyperactive Member
Originally posted by The Hobo
If someone reposts your code but completely working, I'm going to be horribly disappointed that they'd do such a thing.
agreed.
-
Nov 6th, 2002, 10:23 PM
#10
Thread Starter
Lively Member
your right, i'm sorry for asking thank you for your help so far.
-
Nov 6th, 2002, 10:27 PM
#11
Thread Starter
Lively Member
but does this method account for leap years and the whole some months have 30 days others have 31 and fabruary has 28?
-
Nov 6th, 2002, 10:28 PM
#12
Stuck in the 80s
Originally posted by Supreme Cookie
your right, i'm sorry for asking thank you for your help so far.
Give it a go and if you're having problems, we'd be glad to help.
-
Nov 6th, 2002, 10:29 PM
#13
Stuck in the 80s
Originally posted by Supreme Cookie
but does this method account for leap years and the whole some months have 30 days others have 31 and fabruary has 28?
You betcha. It's all built in there.
-
Nov 6th, 2002, 10:30 PM
#14
Thread Starter
Lively Member
now that's just plain fancy....
-
Nov 6th, 2002, 10:31 PM
#15
Hyperactive Member
Originally posted by Supreme Cookie
now that's just plain fancy....
Easy huh? 
saves a ton of your code too
-
Nov 6th, 2002, 10:32 PM
#16
Stuck in the 80s
And it cuts out a lot of code too.
-
Nov 6th, 2002, 10:38 PM
#17
Thread Starter
Lively Member
hmmm....i'm doing something wrong but i'm not sure why it's won't let me use variables here where it days ddate = m2/d2/y2
sorry if I sound like a real n00b but that's what i am
-
Nov 6th, 2002, 10:38 PM
#18
Thread Starter
Lively Member
Option Explicit
Dim d1 As Long
Dim m1 As Long
Dim y1 As Long
Private Sub cmdcompute_Click()
picfee.Cls
Dim Name As String
Dim Book As String
Dim CheckMonth As String
Dim CheckDay As String
Dim CheckYear As String
Dim m2 As Long
Dim d2 As Long
Dim y2 As Long
Dim dDate As Date
txtduemonth.Text = m2
txtdueday.Text = d2
txtdueyear.Text = y2
dDate = m2 / d2 / y2 <---see there i think is where i'm messing up
MsgBox DateDiff("d", Now, dDate)
Name = txtname.Text
Book = txtbook.Text
CheckMonth = txtcheckmonth.Text
CheckDay = txtcheckday.Text
CheckYear = txtcheckyear.Text
picfee.Print Name; " now owes for the book" & Book; " that was checked out on" & CheckMonth; " - " & CheckDay; " - " & CheckYear; ""
End Sub
Private Sub Form_Load()
lbldate.Caption = Format(Now, "dddd, mmmm, dd, yyyy")
m1 = Month(Now)
d1 = Day(Now)
y1 = Year(Now)
txttodaymonth.Text = m1
txttodayday.Text = d1
txttodayyear.Text = y1
End Sub
Private Sub Timer1_Timer()
If lbltime.Caption <> CStr(Time) Then
lbltime.Caption = Time
End If
End Sub
-
Nov 6th, 2002, 10:41 PM
#19
Stuck in the 80s
pretty close. Since \ is part of a string, you need to surround it with quotes:
VB Code:
dDate = m2 & "/" & d2 & "/" & y2
-
Nov 6th, 2002, 10:42 PM
#20
Thread Starter
Lively Member
-
Nov 6th, 2002, 10:43 PM
#21
Stuck in the 80s
and the & sign is the concea...tation character. It adds parts of strings together. (sorry, I can never remember that 'c' word)
But:
VB Code:
Msgbox "Dog" & " is " & "cool!"
Will give you "Dog is cool!" in the MessageBox.
-
Nov 6th, 2002, 10:44 PM
#22
Hyperactive Member
You see how you're formatting the lblCaption date, do the same with your d2-m2-y2 thingame when you put it into the date variable.
eg
Code:
dim x as date
x = format(days1 & "-" & months1 & "-" & years1, "dd-mmm-yyyy")
oh and the word is concatenation... (kon-cat-in-ay-shon) 
(ok pick the dude that was a human dictionary in school)
-
Nov 6th, 2002, 10:45 PM
#23
Thread Starter
Lively Member
hmmmm.....it keeps wanting an end of statement after i formated it like you have it there i even tried semicolons and no dice it keeps highlighting the "/"
-
Nov 6th, 2002, 10:46 PM
#24
Thread Starter
Lively Member
-
Nov 6th, 2002, 10:48 PM
#25
Hyperactive Member
Oh you may want to format it the way you use it over there
eg
mm-dd-yyyy
instead of
dd-mm-yyyy
-
Nov 6th, 2002, 10:53 PM
#26
Thread Starter
Lively Member
for the date diff what is the interval as string thing??
-
Nov 6th, 2002, 10:54 PM
#27
Stuck in the 80s
Originally posted by Supreme Cookie
for the date diff what is the interval as string thing??
If you want days, it's "d" with quotes around it.
-
Nov 6th, 2002, 10:56 PM
#28
Hyperactive Member
The Help file has all the variations for that... look in there for more
-
Nov 6th, 2002, 10:57 PM
#29
Thread Starter
Lively Member
ah ok i gotcha now should i dim the m2, y2 and d2 as date or shall i leave them as long?
-
Nov 6th, 2002, 10:58 PM
#30
Hyperactive Member
leave em long
-
Nov 6th, 2002, 11:00 PM
#31
Thread Starter
Lively Member
otay i left em long *snickers* but now i'm getting a type mismatch error on the dDate = line
-
Nov 6th, 2002, 11:01 PM
#32
Stuck in the 80s
You could leave them as long, but I'd put them as integer, since they won't be even close to 32676. And integers only use 16 bytes of memory, rather than 32.
But it doesn't really matter
-
Nov 6th, 2002, 11:02 PM
#33
Stuck in the 80s
Originally posted by Supreme Cookie
otay i left em long *snickers* but now i'm getting a type mismatch error on the dDate = line
What's your exact line?
-
Nov 6th, 2002, 11:02 PM
#34
Thread Starter
Lively Member
ok but i still don't understand the error i'm getting
-
Nov 6th, 2002, 11:03 PM
#35
Hyperactive Member
what does your "line" equal?
-
Nov 6th, 2002, 11:04 PM
#36
Thread Starter
Lively Member
i get a type mismatch on this line:
dDate = Format(m2 & "-" & d2 & "-" & y2, "mm-dd-yyyy")
-
Nov 6th, 2002, 11:04 PM
#37
Hyperactive Member
damn i'm too slow at this
-
Nov 6th, 2002, 11:04 PM
#38
Thread Starter
Lively Member
lol
-
Nov 6th, 2002, 11:06 PM
#39
Stuck in the 80s
Originally posted by Supreme Cookie
i get a type mismatch on this line:
dDate = Format(m2 & "-" & d2 & "-" & y2, "mm-dd-yyyy")
If you're adding the hypens in manually (which you are), then you don't need format.
-
Nov 6th, 2002, 11:06 PM
#40
Stuck in the 80s
If you just do this:
VB Code:
dDate = m2 & "-" & d2 & "-" & y2
Do you get an error?
And all three of those variables are declared Long?
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
|