<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Working with dates in Flex AIR and SQLite</title>
	<atom:link href="http://verysimple.com/2008/09/09/working-with-dates-in-flex-air-and-sqlite/feed/" rel="self" type="application/rss+xml" />
	<link>http://verysimple.com/2008/09/09/working-with-dates-in-flex-air-and-sqlite/</link>
	<description>Custom Software</description>
	<lastBuildDate>Fri, 10 Feb 2012 20:13:26 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Gagi</title>
		<link>http://verysimple.com/2008/09/09/working-with-dates-in-flex-air-and-sqlite/#comment-4427</link>
		<dc:creator>Gagi</dc:creator>
		<pubDate>Thu, 22 Sep 2011 08:39:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.verysimple.com/blog/?p=149#comment-4427</guid>
		<description>Hey Jason,
thank you for your reply.
Would you please give a look to this one last question?

This is my SQLStatement:
public var insertClient:String = &quot;INSERT INTO clients (...status, dateCreated, dateModified, ...) VALUES (... :status, time(&#039;NOW&#039;), time(&#039;NOW&#039;), ....)&quot;;

This stores dates on my database as floats. However, when I use the same statement through an sqlite administrator or command line dates seem to be stored in human readable format (yyyy - mm - dd). I want to store dates on my database, through actionscript code, in yyyy - mm - dd format. do you know if this is possible or not?</description>
		<content:encoded><![CDATA[<p>Hey Jason,<br />
thank you for your reply.<br />
Would you please give a look to this one last question?</p>
<p>This is my SQLStatement:<br />
public var insertClient:String = &#8220;INSERT INTO clients (&#8230;status, dateCreated, dateModified, &#8230;) VALUES (&#8230; :status, time(&#8216;NOW&#8217;), time(&#8216;NOW&#8217;), &#8230;.)&#8221;;</p>
<p>This stores dates on my database as floats. However, when I use the same statement through an sqlite administrator or command line dates seem to be stored in human readable format (yyyy &#8211; mm &#8211; dd). I want to store dates on my database, through actionscript code, in yyyy &#8211; mm &#8211; dd format. do you know if this is possible or not?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason</title>
		<link>http://verysimple.com/2008/09/09/working-with-dates-in-flex-air-and-sqlite/#comment-4425</link>
		<dc:creator>Jason</dc:creator>
		<pubDate>Wed, 21 Sep 2011 15:47:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.verysimple.com/blog/?p=149#comment-4425</guid>
		<description>Julian dates are stored in the DB as a float.  This is what Flex seems to like - you could think of them as serialized dates.  If you want to visually read them straight out of the database then you can format them to display however you want.

Above is a section I wrote &quot;Formatting a Julian date manually in SQL so you can read it&quot; that will show you how you can visually look at dates in the database through a query browser.

Keep in mind this is not how you want to format your SQL statements in your app - this is just for visually inspecting the database.</description>
		<content:encoded><![CDATA[<p>Julian dates are stored in the DB as a float.  This is what Flex seems to like &#8211; you could think of them as serialized dates.  If you want to visually read them straight out of the database then you can format them to display however you want.</p>
<p>Above is a section I wrote &#8220;Formatting a Julian date manually in SQL so you can read it&#8221; that will show you how you can visually look at dates in the database through a query browser.</p>
<p>Keep in mind this is not how you want to format your SQL statements in your app &#8211; this is just for visually inspecting the database.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gagi</title>
		<link>http://verysimple.com/2008/09/09/working-with-dates-in-flex-air-and-sqlite/#comment-4424</link>
		<dc:creator>Gagi</dc:creator>
		<pubDate>Wed, 21 Sep 2011 14:33:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.verysimple.com/blog/?p=149#comment-4424</guid>
		<description>Hey Jason,
am I missing something, or is the statement:
SELECT STRFTIME(‘%J’,my_column) as my_column from my_table

actually wrong?

I reached the desired effect with:
SELECT time(dateCreated) as dateCreated from clients;

However, this is not the problem that brought me here. Rather, I am having difficulties with storing dates on my sqlite table through actionscript.

My data type for my date column on my table is DATE, and I am referencing an actionscript Date object when executing my INSERT statement, but the values for my date (dateCreated) column keep appearing as numbers, not formated as desired: yyyy, mm, dd, hh:mm:ss!

Since I noticed Paul&#039;s comment to be two and a half years old, and since his advice does not seem to be working in my case, I was wondering if you know what could be the issue... perhaps something changed since march 2009?</description>
		<content:encoded><![CDATA[<p>Hey Jason,<br />
am I missing something, or is the statement:<br />
SELECT STRFTIME(‘%J’,my_column) as my_column from my_table</p>
<p>actually wrong?</p>
<p>I reached the desired effect with:<br />
SELECT time(dateCreated) as dateCreated from clients;</p>
<p>However, this is not the problem that brought me here. Rather, I am having difficulties with storing dates on my sqlite table through actionscript.</p>
<p>My data type for my date column on my table is DATE, and I am referencing an actionscript Date object when executing my INSERT statement, but the values for my date (dateCreated) column keep appearing as numbers, not formated as desired: yyyy, mm, dd, hh:mm:ss!</p>
<p>Since I noticed Paul&#8217;s comment to be two and a half years old, and since his advice does not seem to be working in my case, I was wondering if you know what could be the issue&#8230; perhaps something changed since march 2009?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason</title>
		<link>http://verysimple.com/2008/09/09/working-with-dates-in-flex-air-and-sqlite/#comment-4410</link>
		<dc:creator>Jason</dc:creator>
		<pubDate>Thu, 15 Sep 2011 17:43:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.verysimple.com/blog/?p=149#comment-4410</guid>
		<description>really you can store dates any way you want and inserting into the DB is easy.  But if you plan to use SQLStatement.itemClass so that your sql queries are returned as strongly-typed objects then you may run into casting errors when selecting data.  You can get around it using the workaround statement mentioned above:

SELECT STRFTIME(&#039;%J&#039;,my_column) as my_column from my_table

then AIR will be able to cast the value of my_column as a date</description>
		<content:encoded><![CDATA[<p>really you can store dates any way you want and inserting into the DB is easy.  But if you plan to use SQLStatement.itemClass so that your sql queries are returned as strongly-typed objects then you may run into casting errors when selecting data.  You can get around it using the workaround statement mentioned above:</p>
<p>SELECT STRFTIME(&#8216;%J&#8217;,my_column) as my_column from my_table</p>
<p>then AIR will be able to cast the value of my_column as a date</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Speedy</title>
		<link>http://verysimple.com/2008/09/09/working-with-dates-in-flex-air-and-sqlite/#comment-4409</link>
		<dc:creator>Speedy</dc:creator>
		<pubDate>Thu, 15 Sep 2011 15:33:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.verysimple.com/blog/?p=149#comment-4409</guid>
		<description>Hi Jason,
I just found this page while researching an error #3115 in an AIR SQLite database. You have a lot of interesting info here, so thanks for that.

I already designed my Sqllite db a little differently, storing the DATE as an integer which I get by converting an AS3 Date object using the getTime() method. This returns the number of milliseconds since 1/1/1970. It&#039;s pretty simple to convert back and forth from dates to integers using the getTime() and setTime() functions and so I haven&#039;t run into any reasons not to do store dates this way.

I would appreciate any comments you may have on this method, especially if you see something which could cause a problem for me in the future. For instance, this method would not store the time zone information. But AS3 always adds the local TZ to any new Date object so I didn&#039;t see that as an issue. Anything you see that I&#039;m missing?

Thanks!</description>
		<content:encoded><![CDATA[<p>Hi Jason,<br />
I just found this page while researching an error #3115 in an AIR SQLite database. You have a lot of interesting info here, so thanks for that.</p>
<p>I already designed my Sqllite db a little differently, storing the DATE as an integer which I get by converting an AS3 Date object using the getTime() method. This returns the number of milliseconds since 1/1/1970. It&#8217;s pretty simple to convert back and forth from dates to integers using the getTime() and setTime() functions and so I haven&#8217;t run into any reasons not to do store dates this way.</p>
<p>I would appreciate any comments you may have on this method, especially if you see something which could cause a problem for me in the future. For instance, this method would not store the time zone information. But AS3 always adds the local TZ to any new Date object so I didn&#8217;t see that as an issue. Anything you see that I&#8217;m missing?</p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew</title>
		<link>http://verysimple.com/2008/09/09/working-with-dates-in-flex-air-and-sqlite/#comment-4374</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Sun, 28 Aug 2011 19:08:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.verysimple.com/blog/?p=149#comment-4374</guid>
		<description>Hi Paul

Is there a trick to updating a DATE column?
I am passing an AS3 Date obj in the SQLite statement but is not working.</description>
		<content:encoded><![CDATA[<p>Hi Paul</p>
<p>Is there a trick to updating a DATE column?<br />
I am passing an AS3 Date obj in the SQLite statement but is not working.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew</title>
		<link>http://verysimple.com/2008/09/09/working-with-dates-in-flex-air-and-sqlite/#comment-3478</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Fri, 08 Jul 2011 23:29:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.verysimple.com/blog/?p=149#comment-3478</guid>
		<description>So, I figured I&#039;d add my experience. My data is written using a java application via Hibernate (persistence manager). I&#039;m used to working in mysql/java so I strongly type the database like I would there even though it is probably pointless. All my date and time columns are DATETIME in the database. Hibernate (for wrong or right) stores dates to the DB using unix milisecond epoch time. This is probably an artifact of how the data normally travels to and from other DB engines. The Hibernate dialect (the thing that handles all these details) is pretty simple. I suppose I could have changed this there, but I digress. 

The interesting thing for me was that queries like this:

SELECT MIN(someDateTime) AS d FROM SomeTable

would work if I then wrapped the results in a new Date(r[&#039;d&#039;]). The value in &#039;d&#039; was the literal epoch time in miliseconds. 

What didn&#039;t work was just querying the date directly. It always came back as null. What I figured out (thanks to your post) is that AS was trying to coerce the date in the simple query into a date and failing. In the MIN/MAX (and I assume any other aggregate method) AS couldn&#039;t tell the type so it just guessed number... 

For me, because the data I&#039;m working with only has second level precision to start with, I just modified my queries thusly:

SELECT ... DATETIME(someDateTime/1000, &#039;unixepoch&#039;) .... 

In my case java stores all dates in UTC, so if you want this to be local, you could add &#039;local&#039; right after &#039;unixepoch&#039; and sqlite would handle the timezone conversion. 

The /1000 is because sqlite only understands unix epoch in seconds. I suppose I could also have just changed the column type to be int or something else NOT datetime and my new Date(...) trick from MIN/MAX would have worked. Still, a little insane.</description>
		<content:encoded><![CDATA[<p>So, I figured I&#8217;d add my experience. My data is written using a java application via Hibernate (persistence manager). I&#8217;m used to working in mysql/java so I strongly type the database like I would there even though it is probably pointless. All my date and time columns are DATETIME in the database. Hibernate (for wrong or right) stores dates to the DB using unix milisecond epoch time. This is probably an artifact of how the data normally travels to and from other DB engines. The Hibernate dialect (the thing that handles all these details) is pretty simple. I suppose I could have changed this there, but I digress. </p>
<p>The interesting thing for me was that queries like this:</p>
<p>SELECT MIN(someDateTime) AS d FROM SomeTable</p>
<p>would work if I then wrapped the results in a new Date(r['d']). The value in &#8216;d&#8217; was the literal epoch time in miliseconds. </p>
<p>What didn&#8217;t work was just querying the date directly. It always came back as null. What I figured out (thanks to your post) is that AS was trying to coerce the date in the simple query into a date and failing. In the MIN/MAX (and I assume any other aggregate method) AS couldn&#8217;t tell the type so it just guessed number&#8230; </p>
<p>For me, because the data I&#8217;m working with only has second level precision to start with, I just modified my queries thusly:</p>
<p>SELECT &#8230; DATETIME(someDateTime/1000, &#8216;unixepoch&#8217;) &#8230;. </p>
<p>In my case java stores all dates in UTC, so if you want this to be local, you could add &#8216;local&#8217; right after &#8216;unixepoch&#8217; and sqlite would handle the timezone conversion. </p>
<p>The /1000 is because sqlite only understands unix epoch in seconds. I suppose I could also have just changed the column type to be int or something else NOT datetime and my new Date(&#8230;) trick from MIN/MAX would have worked. Still, a little insane.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dates in Flex, AIR, SQLITE, And ActionScript &#171; Charlie&#039;s Flex Blog</title>
		<link>http://verysimple.com/2008/09/09/working-with-dates-in-flex-air-and-sqlite/#comment-590</link>
		<dc:creator>Dates in Flex, AIR, SQLITE, And ActionScript &#171; Charlie&#039;s Flex Blog</dc:creator>
		<pubDate>Sat, 09 Jan 2010 21:01:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.verysimple.com/blog/?p=149#comment-590</guid>
		<description>[...] you can safely store Dates as TEXT or DATE types in SQLITE, but if you store it as DATE, then AIR will convert the date value to the DOUBLE format (julian date), which for most humans is not readable as a [...]</description>
		<content:encoded><![CDATA[<p>[...] you can safely store Dates as TEXT or DATE types in SQLITE, but if you store it as DATE, then AIR will convert the date value to the DOUBLE format (julian date), which for most humans is not readable as a [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason</title>
		<link>http://verysimple.com/2008/09/09/working-with-dates-in-flex-air-and-sqlite/#comment-589</link>
		<dc:creator>Jason</dc:creator>
		<pubDate>Mon, 19 Oct 2009 17:04:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.verysimple.com/blog/?p=149#comment-589</guid>
		<description>Hey Tim, try running you query directly using something like &lt;a href=&quot;https://addons.mozilla.org/en-US/firefox/addon/5817&quot; rel=&quot;nofollow&quot;&gt;SQL Query Manager&lt;/a&gt; first.  If it runs fine there, then you can look further into AIR.  It sounds like you may just have an error in your SQL statement, though.</description>
		<content:encoded><![CDATA[<p>Hey Tim, try running you query directly using something like <a href="https://addons.mozilla.org/en-US/firefox/addon/5817" rel="nofollow">SQL Query Manager</a> first.  If it runs fine there, then you can look further into AIR.  It sounds like you may just have an error in your SQL statement, though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim</title>
		<link>http://verysimple.com/2008/09/09/working-with-dates-in-flex-air-and-sqlite/#comment-588</link>
		<dc:creator>Tim</dc:creator>
		<pubDate>Thu, 15 Oct 2009 23:20:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.verysimple.com/blog/?p=149#comment-588</guid>
		<description>I am getting the error on a SELECT query and none of the tables has any kind of date column. The datatypes are:

int
varchar(255)
varchar(1)
bit
varchar(50)
varchar(8)</description>
		<content:encoded><![CDATA[<p>I am getting the error on a SELECT query and none of the tables has any kind of date column. The datatypes are:</p>
<p>int<br />
varchar(255)<br />
varchar(1)<br />
bit<br />
varchar(50)<br />
varchar(8)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

