アプリ版:「スタンプのみでお礼する」機能のリリースについて

VB6で開発をしています。
YYMMDD形式で日付をあらわした2つの文字列に、日単位で何日差があるのかを調べるいい方法はないでしょうか?
うるう年があったりして、いい方法がみつからなくてこまっています。

A 回答 (3件)

'Form1にテキストボックスを二つ、コマンドボタンをひとつ貼り付けて実行してみてください。


Private Sub Command1_Click()
Dim dtDate1 As Date, dtDate2 As Date, lngDiffDate As Long
dtDate1 = CDate(Form1.Text1)
dtDate2 = CDate(Form1.Text2)
lngDiffDate = DateDiff("d", dtDate1, dtDate2)
MsgBox lngDiffDate & " 日です。"
End Sub

'以上
    • good
    • 0
この回答へのお礼

バッチりでした!
ログインパスワードを忘れてしまい、お礼が大変遅れてしまいました。
ありがとうございました。

お礼日時:2009/07/22 22:13

例として


Sub tst02()
a = "020324"
t1 = Format(a, "00/00/00")
t2 = CDate(t1)
MsgBox t2
b = "020314"
t3 = Format(b, "00/00/00")
t4 = CDate(t3)
MsgBox t4
ret = DateDiff("d", t4, t2)
MsgBox ret
End Sub
結果は10
ーー
VB6でやってみて、CDateで日付化できませんか。
出来れば2つの文字列を日付化しDateDiffで引き算する。
    • good
    • 0

'No.1です。

YYMMDD形式を忘れていました。
'以下の通り修正してください。
Private Sub Command1_Click()
Dim dtDate1 As Date, dtDate2 As Date, lngDiffDate As Long
Dim stryear1 As String, strMonth1 As String, strDay1 As String
Dim stryear2 As String, strMonth2 As String, strDay2 As String

With Form1
stryear1 = "20" & Mid(.Text1, 1, 2)
strMonth1 = Mid(.Text1, 3, 2)
strDay1 = Mid(.Text1, 5, 2)
stryear2 = "20" & Mid(.Text2, 1, 2)
strMonth2 = Mid(.Text2, 3, 2)
strDay2 = Mid(.Text2, 5, 2)
End With

dtDate1 = CDate(stryear1 & "/" & strMonth1 & "/" & strDay1)
dtDate2 = CDate(stryear2 & "/" & strMonth2 & "/" & strDay2)

lngDiffDate = DateDiff("d", dtDate1, dtDate2)
MsgBox lngDiffDate & " 日です。"
End Sub
'以上
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!