[wp-hackers] Saving DATETIME with $wpdb->insert ?
John Blackbourn
johnbillion+wp at gmail.com
Fri Jan 31 01:27:00 UTC 2014
A date in DATETIME format ("YYYY-MM-DD HH:MM:SS") is a string, not a
number. You need to use %s instead of %d, as you pointed out.
John
On 31 January 2014 01:10, BenderisGreat <greglancaster71 at gmail.com> wrote:
> Having an issue while saving datetime in the db. Insert is a success with
> the exception of the datetime field which remains as 0000-00-00 00:00:00.
> Not sure why, I am using wordpress' current_time('mysql', 1) format. Also
> tried date('Y-m-d h:i:s') without any success. I feel stupid asking this,
> but I really dont understand why this is failing. It saves properly if I
> use
> %s but I read that datetime should not be saved as a string ever on
> stackoverflow.
>
>
>
> $sql2 = $wpdb->insert($activityTable,
> array(
> 'user_id' => $profile_id,
> 'activity_cat' => 'status',
> 'type' => 'status_update',
> 'action' => $actionUpdate,
> 'content' => $statusUpdate,
> 'time' => current_time('mysql', 1)
> ),
> array(
> '%d',
> '%s',
> '%s',
> '%s',
> '%s',
> '%d'
> )
> );
>
>
>
>
> --
> View this message in context:
> http://wordpress-hackers.1065353.n5.nabble.com/Saving-DATETIME-with-wpdb-insert-tp43278.html
> Sent from the Wordpress Hackers mailing list archive at Nabble.com.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list