# How to format a custom field of a date which is stored as Unix timestamp (1592235345)

**URL:** https://forum.pinegrow.com/t/how-to-format-a-custom-field-of-a-date-which-is-stored-as-unix-timestamp-1592235345/4240
**Category:** Pinegrow WP
**Created:** [June 15, 2020, 3:36pm UTC](https://forum.pinegrow.com/t/how-to-format-a-custom-field-of-a-date-which-is-stored-as-unix-timestamp-1592235345/4240 "2020-06-15T15:36:54Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![sitestreet](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/sitestreet/32/41_2.png) [@sitestreet](https://forum.pinegrow.com/u/sitestreet)
#### Post date: [June 15, 2020, 3:36pm UTC](https://forum.pinegrow.com/t/how-to-format-a-custom-field-of-a-date-which-is-stored-as-unix-timestamp-1592235345/4240/1 "2020-06-15T15:36:54Z")

</div>

I have a custom field where the data and time is stored as a Unix timestamp, eg. 1592235345. I want to format this to be 15th June 2020. How do I do this in PG? I know the PHP date format method but not within PG.

---

<div class="post-metadata">

### Author: ![mxs](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/mxs/32/2943_2.png) [@mxs](https://forum.pinegrow.com/u/mxs)
#### Post date: [June 17, 2020, 3:32pm UTC](https://forum.pinegrow.com/t/how-to-format-a-custom-field-of-a-date-which-is-stored-as-unix-timestamp-1592235345/4240/2 "2020-06-17T15:32:30Z")

</div>

tiz a built in php function

\<?php echo date('m/d/Y H:i:s', 1592235345); ?\>

See “timestamp” in [https://www.php.net/manual/en/function.date.php](https://www.php.net/manual/en/function.date.php)

---

<div class="post-metadata">

### Author: ![sitestreet](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/sitestreet/32/41_2.png) [@sitestreet](https://forum.pinegrow.com/u/sitestreet)
#### Post date: [June 17, 2020, 3:45pm UTC](https://forum.pinegrow.com/t/how-to-format-a-custom-field-of-a-date-which-is-stored-as-unix-timestamp-1592235345/4240/3 "2020-06-17T15:45:19Z")

</div>

Thanks @mxs. I know about that, it’s how to do it within Pinegrow I’m not sure of. How would I do that?

---

<div class="post-metadata">

### Author: ![RobM](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@RobM](https://forum.pinegrow.com/u/RobM)
#### Post date: [June 17, 2020, 6:18pm UTC](https://forum.pinegrow.com/t/how-to-format-a-custom-field-of-a-date-which-is-stored-as-unix-timestamp-1592235345/4240/4 "2020-06-17T18:18:59Z")

</div>

What type of page are you putting together? Where is the timestamp data coming from?

---

<div class="post-metadata">

### Author: ![sitestreet](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/sitestreet/32/41_2.png) [@sitestreet](https://forum.pinegrow.com/u/sitestreet)
#### Post date: [June 17, 2020, 6:20pm UTC](https://forum.pinegrow.com/t/how-to-format-a-custom-field-of-a-date-which-is-stored-as-unix-timestamp-1592235345/4240/5 "2020-06-17T18:20:29Z")

</div>

It’s an archive page for a custom post type created with Toolset. I’m displaying a custom field (date) which Toolset stores as a Unix timestamp.

---

<div class="post-metadata">

### Author: ![droidgoo](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/droidgoo/32/2209_2.png) [@droidgoo](https://forum.pinegrow.com/u/droidgoo)
#### Post date: [June 18, 2020, 2:28am UTC](https://forum.pinegrow.com/t/how-to-format-a-custom-field-of-a-date-which-is-stored-as-unix-timestamp-1592235345/4240/6 "2020-06-18T02:28:23Z")

</div>

shouldn’t toolset offer that option on the format?

> **[Toolset - Build Beautiful Dynamic WordPress Websites](https://toolset.com/)**
>
> Posts and pages aren’t enough for every site. Toolset lets you build your own listing sites, directories, membership sites, and shops.

i mean they say it has “everything you need” 😉

---

<div class="post-metadata">

### Author: ![sitestreet](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/sitestreet/32/41_2.png) [@sitestreet](https://forum.pinegrow.com/u/sitestreet)
#### Post date: [June 18, 2020, 7:56am UTC](https://forum.pinegrow.com/t/how-to-format-a-custom-field-of-a-date-which-is-stored-as-unix-timestamp-1592235345/4240/7 "2020-06-18T07:56:56Z")

</div>

I know what you mean. However, a custom date field created by Toolset uses the Unix timestamp value instead of yyyy-mm-dd as a standard MySQL date field would. No idea why, but it does. So, when I show that on a page, I need to convert it back to a regular format. This is what I’m struggling with in Pinegrow. I’m sure I’ve achieved this in the past but I just can’t remember how and I’ve looked back through old projects and can’t find it there, either.

When showing a field on a page, I just need to know how I can use PHP to manipulate that field. That’s effectively what I’m after.

---

<div class="post-metadata">

### Author: ![droidgoo](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/droidgoo/32/2209_2.png) [@droidgoo](https://forum.pinegrow.com/u/droidgoo)
#### Post date: [June 18, 2020, 2:08pm UTC](https://forum.pinegrow.com/t/how-to-format-a-custom-field-of-a-date-which-is-stored-as-unix-timestamp-1592235345/4240/8 "2020-06-18T14:08:55Z")

</div>

you need to embed a php command in your html that will will convert the format to what you want displayed and the echo that to your page as it is served up to the browser. if that toolkit doesn’t offer such functionality, then you will have to dive deeper into server side php than you bargained for.

i don’t know of any client side manipulations that can be done, but i’m sure there’s a js for that.

---

<div class="post-metadata">

### Author: ![sitestreet](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/sitestreet/32/41_2.png) [@sitestreet](https://forum.pinegrow.com/u/sitestreet)
#### Post date: [June 18, 2020, 2:24pm UTC](https://forum.pinegrow.com/t/how-to-format-a-custom-field-of-a-date-which-is-stored-as-unix-timestamp-1592235345/4240/9 "2020-06-18T14:24:28Z")

</div>

Thanks @droidgoo. What’s the technique for using PHP within the Pinegrow system? Or should I create a shortcode in the functions file? Seems overkill for what I want.

---

<div class="post-metadata">

### Author: ![droidgoo](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/droidgoo/32/2209_2.png) [@droidgoo](https://forum.pinegrow.com/u/droidgoo)
#### Post date: [June 18, 2020, 3:01pm UTC](https://forum.pinegrow.com/t/how-to-format-a-custom-field-of-a-date-which-is-stored-as-unix-timestamp-1592235345/4240/10 "2020-06-18T15:01:56Z")

</div>

you open a php command using the tag

`<?php // do some commands ?>`

but the trick is to tell ur server to parse all your .html as .php code so ti will get picked up.

to you it looks and acts just like .html, but to the server it’s .php with some (a lot 😉 ) of .html tags in it.

you do this by using the .htaccess file you probably already have at your root dir for identifying the path to your 404.html page.

for my server the designation was

`AddType x-mapp-php5.5 .html .htm`

yours will probably be different

you can find out what the php SERVER\_NAME is called by creating a .php file on the server with this php code and then directing your browser to it on the server to see the output.

[https://www.w3schools.com/php/php\_superglobals\_server.asp](https://www.w3schools.com/php/php_superglobals_server.asp)

i relied heavily on this resource and searching stackoverflow a lot (like a lot a lot)

---

<div class="post-metadata">

### Author: ![sitestreet](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/sitestreet/32/41_2.png) [@sitestreet](https://forum.pinegrow.com/u/sitestreet)
#### Post date: [June 18, 2020, 3:05pm UTC](https://forum.pinegrow.com/t/how-to-format-a-custom-field-of-a-date-which-is-stored-as-unix-timestamp-1592235345/4240/11 "2020-06-18T15:05:53Z")

</div>

Thanks again @droidgoo but it’s the technique needed in Pinegrow I need a steer on. What Wordpress action should I use to echo a custom field within PHP so I can modify it?

---

<div class="post-metadata">

### Author: ![droidgoo](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/droidgoo/32/2209_2.png) [@droidgoo](https://forum.pinegrow.com/u/droidgoo)
#### Post date: [June 18, 2020, 4:27pm UTC](https://forum.pinegrow.com/t/how-to-format-a-custom-field-of-a-date-which-is-stored-as-unix-timestamp-1592235345/4240/12 "2020-06-18T16:27:05Z")

</div>

i only have PG Pro, so when i activate the `PHP, ASP, ERB` extension, all i get is the ability to toggle to php code on/off in the PG live screen area.

maybe that extension does more in PG WP edition?

---

<div class="post-metadata">

### Author: ![sitestreet](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/sitestreet/32/41_2.png) [@sitestreet](https://forum.pinegrow.com/u/sitestreet)
#### Post date: [June 18, 2020, 4:46pm UTC](https://forum.pinegrow.com/t/how-to-format-a-custom-field-of-a-date-which-is-stored-as-unix-timestamp-1592235345/4240/13 "2020-06-18T16:46:23Z")

</div>

Aah, the WP actions are completely different.

@matjaz or @Emmanuel , can you steer me in the right direction?

---

<div class="post-metadata">

### Author: ![Emmanuel](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/emmanuel/32/6294_2.png) [@Emmanuel](https://forum.pinegrow.com/u/Emmanuel)
#### Post date: [June 19, 2020, 9:44am UTC](https://forum.pinegrow.com/t/how-to-format-a-custom-field-of-a-date-which-is-stored-as-unix-timestamp-1592235345/4240/14 "2020-06-19T09:44:36Z")

</div>

@sitestreet Like this:

 ![2020-06-19_11-41-10](https://canada1.discourse-cdn.com/flex036/uploads/pinegrow/original/2X/2/2dad39a50de8e9cac8f3ad0eba77d718be9cc46b.jpeg)

Result:

 ![2020-06-19_11-43-56](https://canada1.discourse-cdn.com/flex036/uploads/pinegrow/original/2X/6/6531b0492b39b45f6bd8eeb3860225851619f451.jpeg)

---

<div class="post-metadata">

### Author: ![sitestreet](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/sitestreet/32/41_2.png) [@sitestreet](https://forum.pinegrow.com/u/sitestreet)
#### Post date: [June 19, 2020, 11:05am UTC](https://forum.pinegrow.com/t/how-to-format-a-custom-field-of-a-date-which-is-stored-as-unix-timestamp-1592235345/4240/15 "2020-06-19T11:05:44Z")

</div>

Thanks @Emmanuel. How would I use the custom field instead of the static value? I have a field called wpcf-created-date

Cheers.
