vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   change time format inside of query (https://vborg.vbsupport.ru/showthread.php?t=318290)

mohammad6006 04-17-2015 06:34 PM

change time format inside of query
 
How can I change lastavtivity format and add to another table?

PHP Code:

$vbulletin->db->query_write("
                    INSERT INTO `"
TABLE_PREFIX ."mba_hozor`
                    (userid, dateline, date)
                    SELECT userid, lastactivity , " 
.vbdate('Y-m-d'lastactivity)."
                    FROM " 
TABLE_PREFIX "user
                "
); 

vbdate('Y-m-d', lastactivity) not work in query

kh99 04-17-2015 06:36 PM

I think you want to use the mysql function FROM_UNIXTIME(). Here's the documentation: http://dev.mysql.com/doc/refman/5.5/..._from-unixtime

mohammad6006 04-17-2015 06:45 PM

Quote:

Originally Posted by kh99 (Post 2543382)
I think you want to use the mysql function FROM_UNIXTIME(). Here's the documentation: http://dev.mysql.com/doc/refman/5.5/..._from-unixtime

vbdate('Y-m-d', lastactivity) work out of the query

for example if I fetch query and store in variable like: $visitor[lastactivity] and then
vbdate('Y-m-d', $visitor[lastactivity]) was working

my problem is that i can not use it in the query

kh99 04-17-2015 06:51 PM

Quote:

Originally Posted by mohammad6006 (Post 2543383)
vbdate('Y-m-d', lastactivity) work out of the query

for example if I fetch query and store in variable like: $visitor[lastactivity] and then
vbdate('Y-m-d', $visitor[lastactivity]) was working

my problem is that i can not use it in the query

You would either have to figure out how to use FROM_UNIXTIME() in the query, or else write a loop to read each row from the user table, use vbdate to convert, then do a separate INSERT for each.

I forgot that vbdate handles the timezone conversion based on a user's selecte timezone. Do you want the times to be converted for each user's timezone, or just for your own?

mohammad6006 04-17-2015 06:58 PM

Quote:

Originally Posted by kh99 (Post 2543384)
You would either have to figure out how to use FROM_UNIXTIME() in the query, or else write a loop to read each row from the user table, use vbdate to convert, then do a separate INSERT for each.

I forgot that vbdate handles the timezone conversion based on a user's selecte timezone. Do you want the times to be converted for each user's timezone, or just for your own?

that is not important

I created a table with 3 columns : userid, dateline, date

I could select userid and lastactivity from "user" table and insert to userid and dateline in this table

but i want to convert lastactivity to Y-m-d format and insert into date column too

kh99 04-17-2015 07:12 PM

OK, then how about this:
PHP Code:

$vbulletin->db->query_write(
                    INSERT INTO `"
TABLE_PREFIX ."mba_hozor` 
                    (userid, dateline, date) 
                    SELECT userid, lastactivity, FROM_UNIXTIME(lastactivity, '%Y-%m-%d') 
                    FROM " 
TABLE_PREFIX "user 
                "
); 



All times are GMT. The time now is 07:21 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01662 seconds
  • Memory Usage 1,732KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete