<?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; numeral</title>
	<atom:link href="http://www.openscriptsolution.com/tag/numeral/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 Convert 10 Digits Numeral to The Date Value?</title>
		<link>http://www.openscriptsolution.com/2009/08/29/how-to-convert-10-digits-numeral-to-the-date-value/</link>
		<comments>http://www.openscriptsolution.com/2009/08/29/how-to-convert-10-digits-numeral-to-the-date-value/#comments</comments>
		<pubDate>Sat, 29 Aug 2009 11:17:29 +0000</pubDate>
		<dc:creator>Masino Sinaga</dc:creator>
				<category><![CDATA[Date and Time]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[digits]]></category>
		<category><![CDATA[numeral]]></category>

		<guid isPermaLink="false">http://www.openscriptsolution.com/?p=137</guid>
		<description><![CDATA[I have hundreds of records that need to be imported from one table and database (let&#8217;s say that this is the first database) to another table in different database (and the last one is the second database). Unfortunately, one of the columns in the table in first database has the Date value in 10 digits [...]]]></description>
			<content:encoded><![CDATA[<p>I have hundreds of records that need to be imported from one table and database (let&#8217;s say that this is the first database) to another table in different database (and the last one is the second database). Unfortunately, one of the columns in the table in first database has the Date value in 10 digits numeral format. For example: <strong>1206980969</strong>. Actually, this value equals with <strong>March 31, 2008 16:29:29 on UTC</strong>. Then, how do I convert that 10 digits numeral to the Data value since the column in the second database is a Date field type? And how do I convert again that date according to my local time?  <span id="more-137"></span></p>
<p>Okay. Here is the solution that I made from Visual Basic 6. First of all, you should create a new function for this.</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
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;"><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;">Private</span> <span style="color: #151B8D; font-weight: bold;">Declare</span> <span style="color: #E56717; font-weight: bold;">Function</span> GetTimeZoneInformation Lib <span style="color: #800000;">&quot;KERNEL32.dll&quot;</span> (lpTimeZoneInformation <span style="color: #151B8D; font-weight: bold;">As</span> TIME_ZONE_INFORMATION) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>
&nbsp;
<span style="color: #E56717; font-weight: bold;">Private</span> <span style="color: #151B8D; font-weight: bold;">Type</span> SYSTEMTIME
   wYear                <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>
   wMonth               <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>
   wDayOfWeek           <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>
   wDay                 <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>
   wHour                <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>
   wMinute              <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>
   wSecond              <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>
   wMilliseconds        <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #151B8D; font-weight: bold;">Type</span>
&nbsp;
<span style="color: #E56717; font-weight: bold;">Private</span> <span style="color: #151B8D; font-weight: bold;">Type</span> TIME_ZONE_INFORMATION
   Bias                 <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>
   StandardName         <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span> * 64
   StandardDate         <span style="color: #151B8D; font-weight: bold;">As</span> SYSTEMTIME
   StandardBias         <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>
   DaylightName         <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span> * 64
   DaylightDate         <span style="color: #151B8D; font-weight: bold;">As</span> SYSTEMTIME
   DaylightBias         <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #151B8D; font-weight: bold;">Type</span>
&nbsp;
<span style="color: #E56717; font-weight: bold;">Private</span> Const TIME_ZONE_ID_DAYLIGHT <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span> = 2
<span style="color: #E56717; font-weight: bold;">Private</span> Const Unix1970   <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span> = 25569 <span style="color: #008000;">'CDbl(DateSerial(1970, 1, 1))
</span>
<span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> Unix2Date(vUnixDate <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;">ByVal</span> bReturnUTC <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Boolean</span>) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>
   Unix2Date = DateAdd(<span style="color: #800000;">&quot;s&quot;</span>, vUnixDate, Unix1970) - IIf(bReturnUTC, 0, GetCurrentTZOffset)
<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;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> GetCurrentTZOffset() <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Double</span>
   <span style="color: #151B8D; font-weight: bold;">Dim</span> tz               <span style="color: #151B8D; font-weight: bold;">As</span> TIME_ZONE_INFORMATION
   <span style="color: #151B8D; font-weight: bold;">Dim</span> lRet             <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Long</span>
   <span style="color: #008000;">'Quickest way to see if we are in
</span>   <span style="color: #008000;">'Daylight savings is to check lRet
</span>   lRet = GetTimeZoneInformation(tz)
   <span style="color: #008000;">'Offset in minutes
</span>   GetCurrentTZOffset = tz.Bias + IIf(lRet = TIME_ZONE_ID_DAYLIGHT, tz.DaylightBias, tz.StandardBias)
   GetCurrentTZOffset = GetCurrentTZOffset / 1440
<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> Command1_Click()
   MsgBox <span style="color: #800000;">&quot;UTC   = &quot;</span> &amp; Unix2Date(1206980969, <span style="color: #00C2FF; font-weight: bold;">True</span>) <span style="color: #008000;">'March 31, 2008 16:29:29 (UTC)
</span>   MsgBox <span style="color: #800000;">&quot;Local = &quot;</span> &amp; Unix2Date(1206980969, <span style="color: #00C2FF; font-weight: bold;">False</span>) <span style="color: #008000;">'March 31, 2008 23:29:29 (UTC + 7)
</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 conclusion is: We can use the Unix2Date function which has two parameters in it. The first parameter is the 10 digits numeral value, and the second parameter is the flag whether you want to convert it to UTC or to your local time. If we want to convert it to UTC, then the second parameter value is <strong>True</strong>, whereas if we want to convert it to the local time (in this case I have UTC + 7), the second parameter value is <strong>False</strong>.</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%2F08%2F29%2Fhow-to-convert-10-digits-numeral-to-the-date-value%2F&amp;title=How%20to%20Convert%2010%20Digits%20Numeral%20to%20The%20Date%20Value%3F" 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/08/29/how-to-convert-10-digits-numeral-to-the-date-value/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
