<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Saw Thawah</title>
    <description>The latest articles on DEV Community by Saw Thawah (@thawahsaw).</description>
    <link>https://dev.to/thawahsaw</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1188389%2F0bcf3b08-d749-4334-b56f-b86301e72672.png</url>
      <title>DEV Community: Saw Thawah</title>
      <link>https://dev.to/thawahsaw</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thawahsaw"/>
    <language>en</language>
    <item>
      <title>How to format date from Firestore in BigQuery</title>
      <dc:creator>Saw Thawah</dc:creator>
      <pubDate>Wed, 18 Oct 2023 13:56:04 +0000</pubDate>
      <link>https://dev.to/thawahsaw/how-to-format-date-from-firestore-in-bigquery-5a56</link>
      <guid>https://dev.to/thawahsaw/how-to-format-date-from-firestore-in-bigquery-5a56</guid>
      <description>&lt;p&gt;Im trying to display dates from Firestore Database in BigQuery.&lt;/p&gt;

&lt;p&gt;Here is an example of my Firestore Document👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.stack.imgur.com/Rp5R0.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x4e9klYo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.stack.imgur.com/Rp5R0.png" alt="Here is an example of my Firestore Document" width="492" height="304"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I would like to display this timestamp, "f58-sodleDate", in BigQuery as 2023-10-3.&lt;/p&gt;

&lt;p&gt;In BigQuery Console, I wrote this code 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;json_extract(data, '$.f58-sodleDate'),
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and I get this 👉 {"_seconds":1691471596,"_nanoseconds":483000000} &lt;/p&gt;

&lt;p&gt;And if I write this code, 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;parse_datetime("%c", JSON_VALUE(DATA, '$.f58-sodleDate')) as dte,

// or this code

JSON_EXTRACT_SCALAR(DATA, '$.f58-sodleDate') AS dte,
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I get the query result as null, like this👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.stack.imgur.com/r2Ah4.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XpEk-zUq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.stack.imgur.com/r2Ah4.png" alt="this query result" width="491" height="166"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And if I write this code👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;date(timestamp_seconds(cast(json_extract(data, '$.f58-sodleDate') as int64))) AS dte,
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I get this error message👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.stack.imgur.com/fcFpu.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7f4TaTGa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.stack.imgur.com/fcFpu.png" alt="error message" width="450" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What I want for my query result is something like this👇&lt;br&gt;
&lt;a href="https://i.stack.imgur.com/ZEKXa.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PPhJ82_S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.stack.imgur.com/ZEKXa.png" alt="correct query result" width="494" height="232"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I achieved this by writing this code 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FORMAT_DATE('%F', timestamp) as dte,
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please tell me what I have to do to achieve the result I want..&lt;/p&gt;

&lt;p&gt;Thank you, best. - STW&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
