Epoch time question

jerkpork

New Member
I have an existing table that I'm trying to display using Fabrik and the table includes a couple of date fields that are currently stored as integers based on epoch time. Is there some easy way to get Fabrik to display these numbers as human readable dates or do I have to recreate the table using a date format? Ideally I would like to continue using epoch time so if that's possible, that would be great.

Btw, I only have a few hours of hands on experience with Fabrik so I really need a for beginners response. :) Thanks so much!
 
H jerk,
if you go to the layout folder of your choosen layout you could add a php or jquery solution to it - i think.
So if you have the default layout for that list you go to VIEWS/LIST/DEFAULT/default.php

you could check via php for the element-row so that when it has the ID of your element that it should be converted into whatever you want.
Or check via jQuery at the end of the page for your field and tell jQuery to change the content into the value you want.

Greetings.
 
Thank you for the response, but I honestly have no idea how to do what you're telling me to do. I guess the answer to my question is that there is no easy way to convert from epoch time using Fabrik ( fyi, to me, "easy" means through the graphic interface ).
 
ok, but do you know a bit of PHP or Javascript? It is not that difficult so that i could help you out.
i am not more than a scriptkid - no PHP or JS mayhem so my solution might not be correct but a first step.
 
You're very kind to offer your assistance, but I think I might be a lost cause. I know next to nothing about php and javascript.

I found this code php code snippet online that shows how to convert an epoch value into a date:

$epoch = 1344988800;
$dt = new DateTime("@$epoch");
echo $dt->format('Y-m-d H:i:s');

Is there an easy way to adapt this code to my situation? Let's say hypothetically that I have 2 date elements, purchase_date, and sale_date and their ID's are 3 and 4.
If it's a simple case of writing a few lines and you could tell me where to plug them in, then I'd be grateful for your help, but if it's a major amount of work, then PLEASE don't go to the trouble.

Thank you again!
 
Ok, maybe the easiest trick would to make the value appear as date (in the Y-m-d H:i:s format) and keep it in epoch value inside your datebase.
What i mean is something like: your template (default.php) gets the DB value (in epoche) and for a millisecond shows it as epoche. You then change that via jQuery.
Ok, let's try the most hardest thing: to get you into the programming fun :)

Please consider this not beeing the most beautiful and recommende way, but it will show you quickly what i want to teach you...
1. Go to your own template folder.
2. open the index.php
3. before the </body> tag appears put in this code:
HTML:
<script>
alert("Here i am");
</script>

If you check your page now, there should be a javascript pop up saying "Here i am".
If this works - fiiiine :)

4. Now remove the alert line.
5. insert this code between the SCRIPT tags you just wrote
HTML:
myDate = new Date(1000*1344988800);
theNewTime = myDate.toString()
alert(theNewTime);
What we have now is that a alert showing "theNewTime".

6. now e will exchange the "fixed" time value (1344988800) in the code above with the value of your list / table field.
To get the value of your field you can use the jquery syntax like this $( "div.demo-container" ).text() or $( "div.demo-container" ).val()

So the code could look something like this:
HTML:
<script>
// this gets the value inside the DIV with the ID "fabrikInput_row___purchase_date" and inserts it into a new variable.
thetimeVal = $("#fabrikInput_row___purchase_date").val();
myDate = new Date(1000*thetimeVal);
theNewTime = myDate.toString()
// this line takes the DIV with the ID farikInput_row___purchase_date and exchanges the text inside it.
$("#fabrikInput_row___purchase_date").val(theNewTime);
</script>

Please be aware this is very raw mode and i have not tested it out. I just want to show you some kind of path how i would archive it.
Good luck my friend! :)
 
Thanks a lot for all this great information! I really appreciate it. I tried what you wrote and everything worked as predicted except for step 6. That's ok, I'll tinker with it some more and maybe I'll eventually get it to work. Thanks again for all your effort!
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top