• Resolved pauhana

    (@pauhana)


    Hello.

    I store dates as timestamps within my DB. When I look at records in the Data Explorer, the info is not presented in human readable form. Is there a way to get Data Explorer to properly present a date that is a timestamp?

    Thanks!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi @pauhana,

    You can change the date format in plugin settings. Just scroll down on tab plugin until you find the date format setting.

    Does this help?
    Peter

    Thread Starter pauhana

    (@pauhana)

    Still unclear.

    Here is a screenshot of my current settings for dates:
    https://ibb.co/GnmbXsg

    My date has been confirmed correct, but shows up within the Data Explorer as
    “November 30, -0001 12:00 am”. Given the date output setting, I was expecting
    “April 11, 2022”.

    Where am I going wrong?

    Thanks for the help!

    Thread Starter pauhana

    (@pauhana)

    Sorry, wrong graphic.

    Date format output (WordPress format) is given as “F j, Y”.

    Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi @pauhana,

    How do you store the timestamp? Can you share the code?

    What output do you get from a stand query in the Query Builder?

    Thanks,
    Peter

    Thread Starter pauhana

    (@pauhana)

    Here’s a snippet of my code:

          $today = strtotime('today PST');
          if ($today !== false) {
            //DBG $page_text .= 'Today is [' . date("Y-m-d", $today) . ']</br>';
            $db_columns = array('svs_seed_order_date' => $today,
                                'svs_seed_order_member_id' => $user_id,
                                'svs_seed_order_set_id' => $new_seed_set_id);
            $wpdb->insert('svs_seed_order', $db_columns, array('%d', '%d','%d'));
          } else {
            $msg = "Internal error: Problem determining today's date.";
          }

    As I say, the value stored has been confirmed to be fine.

    Please let me know if there is a better way to go about storing the date…

    Thread Starter pauhana

    (@pauhana)

    Oh, and as to your second question, the query builder shows the date values to be zeroed out; the date column shows as “0000-00-00 00:00:00”.

    Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi @pauhana,

    I think your code snippet is the problem. The strtotime return an int which MySQL interprets as a wrong format, resulting in a datetime with all zeros. With wpdb->insert it’s better to use current_time:
    https://developer.www.ads-software.com/reference/functions/current_time/

    Does this solve the issue?

    Thanks,
    Peter

    Thread Starter pauhana

    (@pauhana)

    Thank you Peter.

    I ended up having so much trouble trying to get a date interpreted properly, I ended up just storing it as a string. Not optimal, but good enough.

    Thanks again for the help.

    Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi @pauhana,

    Not sure if this is applicable to your situation, but the simplest solution to get rid of these manual actions is to let your DBMS do this for you:

    alter table svs_seed_order modify svs_seed_order_date datetime default current_timestamp on update current_timestamp

    When you remove column svs_seed_order_date from all your insert and update statements your DBMS will keep it up to data for you.

    Hope this helps,
    Peter

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Setting data explorer dates’ is closed to new replies.