<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Open Script Solution&#187; between</title>
	<atom:link href="http://www.openscriptsolution.com/tag/between/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.openscriptsolution.com</link>
	<description>... where solutions for script programming are found ...</description>
	<lastBuildDate>Tue, 31 Jan 2012 03:22:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to Calculate Difference Between Two Dates Using VB6</title>
		<link>http://www.openscriptsolution.com/2009/09/01/how-to-calculate-difference-between-two-dates-using-vb6/</link>
		<comments>http://www.openscriptsolution.com/2009/09/01/how-to-calculate-difference-between-two-dates-using-vb6/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 13:38:35 +0000</pubDate>
		<dc:creator>Masino Sinaga</dc:creator>
				<category><![CDATA[Date and Time]]></category>
		<category><![CDATA[between]]></category>
		<category><![CDATA[calculate]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[dates]]></category>
		<category><![CDATA[difference]]></category>
		<category><![CDATA[hitung]]></category>
		<category><![CDATA[selisih]]></category>
		<category><![CDATA[tanggal]]></category>
		<category><![CDATA[two]]></category>

		<guid isPermaLink="false">http://www.openscriptsolution.com/?p=175</guid>
		<description><![CDATA[This following code will show you how to calculate difference between two dates by using Visual Basic 6. The calculation result will give you an output that contains of the difference between those two dates in format: Days, Hours:Minutes:Seconds. The both dates must be in complete format. For example: the first date is March 1, [...]]]></description>
			<content:encoded><![CDATA[<p>This following code will show you how to calculate difference between two dates by using Visual Basic 6. The calculation result will give you an output that contains of the difference between those two dates in format: <strong>Days, Hours:Minutes:Seconds</strong>. The both dates must be in complete format. For example: the first date is March 1, 2002 17:18:00, and the second date is September 1, 2002 09:42:30. After being calculated, then the output will give you the result as follow: 183 day(s), 16:24:30. It means: The difference between those two dates is: 183 days, 16 hours, 24 minutes, and 30 seconds.<span id="more-175"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #008000;">'Description: Calculate difference between 2 particular dates 
</span><span style="color: #008000;">'             and show the result in format: day(s), hr:min:sec
</span><span style="color: #008000;">'             For example: 
</span><span style="color: #008000;">'             The first date  = 01/03/2002 17:18:00 and 
</span><span style="color: #008000;">'             The second date = 01/09/2002 09:42:30, then
</span><span style="color: #008000;">'             the result will output --&gt; 183 day(s), 16:24:30 
</span><span style="color: #008000;">'             (183 days, 16 hours, 24 minutes, and 30 seconds).
</span><span style="color: #008000;">'             You can use the DateDiff function belongs to VB6
</span><span style="color: #008000;">'Author     : Masino Sinaga 
</span><span style="color: #008000;">'Created    : Sunday, September 1, 2002
</span><span style="color: #008000;">'Preparation: 1. Create a new standar exe project with 1 Form.
</span><span style="color: #008000;">'             2. Add controls: 2 TextBoxes, 1 Label, and 1 Timer.
</span><span style="color: #008000;">'             3. Copy this following code to the form editor form.
</span><span style="color: #008000;">'-------------------------------------------------------------------
</span>
<span style="color: #E56717; font-weight: bold;">Option</span> <span style="color: #E56717; font-weight: bold;">Explicit</span>
&nbsp;
<span style="color: #E56717; font-weight: bold;">Function</span> CalcDiff2Dates(<span style="color: #151B8D; font-weight: bold;">ByVal</span> d1 <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, _
                        <span style="color: #151B8D; font-weight: bold;">ByVal</span> d2 <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>
  <span style="color: #151B8D; font-weight: bold;">Dim</span> Second <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, Day <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>, Hour <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>
  <span style="color: #151B8D; font-weight: bold;">Dim</span> CompleteHour <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>
&nbsp;
  <span style="color: #8D38C9; font-weight: bold;">If</span> d1 &gt; d2 <span style="color: #8D38C9; font-weight: bold;">Then</span>
     MsgBox <span style="color: #800000;">&quot;The first date must be lower than &quot;</span> &amp; _
            <span style="color: #800000;">&quot;the second date!&quot;</span>, _
            vbCritical, <span style="color: #800000;">&quot;Warning&quot;</span>
     <span style="color: #E56717; font-weight: bold;">Exit</span> <span style="color: #E56717; font-weight: bold;">Function</span>
  <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
&nbsp;
  <span style="color: #008000;">'Count the difference in seconds
</span>  Second = DateDiff(<span style="color: #800000;">&quot;s&quot;</span>, d1, d2)
&nbsp;
  <span style="color: #008000;">'Calculate the hour by dividing with 3600
</span>  <span style="color: #008000;">'(backslash (&quot;\&quot;) in order to get the Integer
</span>  <span style="color: #008000;">'without decimal value)
</span>  Hour = Second \ 3600
&nbsp;
  <span style="color: #008000;">'If hour greater than 23
</span>  <span style="color: #008000;">'it means: more than 1 day
</span>  <span style="color: #8D38C9; font-weight: bold;">If</span> Hour &gt; 23 <span style="color: #8D38C9; font-weight: bold;">Then</span>
&nbsp;
     <span style="color: #008000;">'Calculate day by dividing with 24
</span>     <span style="color: #008000;">'(backslash (&quot;\&quot;) in order to get the Integer
</span>     <span style="color: #008000;">'value without decimal value)
</span>     Day = Hour \ 24
&nbsp;
     <span style="color: #008000;">'Calculate the hour duration in hh:mm:ss
</span>     CompleteHour = Format((d2 - d1), <span style="color: #800000;">&quot;hh:mm:ss&quot;</span>)
&nbsp;
  <span style="color: #8D38C9; font-weight: bold;">Else</span> <span style="color: #008000;">'If the hour less than or equal with 23      
</span>
     Day = 0   <span style="color: #008000;">'assign the Day with zero value      
</span>
     <span style="color: #008000;">'Calculate hour duration in hh:mm:ss
</span>     CompleteHour = Format((d2 - d1), <span style="color: #800000;">&quot;hh:mm:ss&quot;</span>)
&nbsp;
  <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>  
&nbsp;
  <span style="color: #8D38C9; font-weight: bold;">If</span> Day = 0 <span style="color: #8D38C9; font-weight: bold;">Then</span>  <span style="color: #008000;">'If less than 1 day
</span>
     <span style="color: #008000;">'Get the final result
</span>     CalcDiff2Dates = CompleteHour
&nbsp;
  <span style="color: #8D38C9; font-weight: bold;">Else</span>  <span style="color: #008000;">'If day greater than 0, show the day duration     
</span>
     <span style="color: #008000;">'Get the final result
</span>     CalcDiff2Dates = Day &amp; <span style="color: #800000;">&quot; day(s), &quot;</span> &amp; CompleteHour
&nbsp;
  <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
&nbsp;
  <span style="color: #E56717; font-weight: bold;">Exit</span> <span style="color: #E56717; font-weight: bold;">Function</span>
&nbsp;
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span>
&nbsp;
<span style="color: #E56717; font-weight: bold;">Private</span> <span style="color: #E56717; font-weight: bold;">Sub</span> Form_Load()
  Timer1.Interval = 500
  Timer1.Enabled = <span style="color: #00C2FF; font-weight: bold;">True</span>
  Text1.Text = <span style="color: #800000;">&quot;01/03/2002 17:18:00&quot;</span>
  <span style="color: #008000;">'Text2.Text = &quot;01/09/2002 09:42:30&quot;
</span>  Text2.Text = Now
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #E56717; font-weight: bold;">Private</span> <span style="color: #E56717; font-weight: bold;">Sub</span> Timer1_Timer()
  <span style="color: #151B8D; font-weight: bold;">On</span> <span style="color: #151B8D; font-weight: bold;">Error</span> <span style="color: #8D38C9; font-weight: bold;">GoTo</span> ErrHandler
  Text2.Text = Now
  Label1.Caption = CalcDiff2Dates(CDate(Text1.Text), _
                      CDate(Text2.Text))
  <span style="color: #E56717; font-weight: bold;">Exit</span> <span style="color: #E56717; font-weight: bold;">Sub</span>
ErrHandler:
  MsgBox <span style="color: #800000;">&quot;Invalid date or format!&quot;</span>, _
         vbCritical, <span style="color: #800000;">&quot;Error Date&quot;</span>
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Sub</span></pre></td></tr></table></div>

<p>From the code above, the first parameter belongs to the <strong>CalcDiff2Dates</strong> function placed on Text1 control, whereas the second parameter placed on Text2 which its value being generated by Timer1 control using time interval one second. </p>
<p>The result being shown at Label1 control based the changes generated by Timer1 control. Of course, you may modify that code above by yourself. For example, by removing the Timer control and disable the Timer code, and then simply use the <strong>CalcDiff2Dates</strong> function only in Form_Load procedure.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.openscriptsolution.com%2F2009%2F09%2F01%2Fhow-to-calculate-difference-between-two-dates-using-vb6%2F&amp;title=How%20to%20Calculate%20Difference%20Between%20Two%20Dates%20Using%20VB6" id="wpa2a_2"><img src="http://www.openscriptsolution.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.openscriptsolution.com/2009/09/01/how-to-calculate-difference-between-two-dates-using-vb6/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
