vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   "datetime" instead of "unsigned int(10)" ? (https://vborg.vbsupport.ru/showthread.php?t=153223)

mihai11 07-24-2007 08:11 AM

"datetime" instead of "unsigned int(10)" ?
 
Hi,

I see that VB is using fields of type "unsigned int(10)" instead of "datetime" to store times. Why is that ? What is the problem with "datetime" ?

Regards,
Razvan M.

Zachery 07-24-2007 08:39 AM

Because vBulletin uses a UNIX timestamp, which is not compatable with datetime in mysql

http://dev.mysql.com/doc/refman/5.0/en/datetime.html

mihai11 07-24-2007 08:43 AM

Quote:

Originally Posted by Zachery (Post 1299933)
Because vBulletin uses a UNIX timestamp, which is not compatable with datetime in mysql

http://dev.mysql.com/doc/refman/5.0/en/datetime.html

I see ...

If I want to insert test data on my database, what MySql function should I use ? Until now I was using the functions "now()" to insert the current time, but that is not working properly with "unsigned int(10)".

Zachery 07-24-2007 08:46 AM

Honestly I got lucky on that one and googled for an anwser, if you need time though TIMENOW works well from the vBulletin engine, and to anwser your other thread, i believe its generated in init.php.

mihai11 07-24-2007 08:50 AM

Quote:

Originally Posted by Zachery (Post 1299939)
Honestly I got lucky on that one and googled for an anwser, if you need time though TIMENOW works well from the vBulletin engine, and to anwser your other thread, i believe its generated in init.php.


You are right ! It is generated like this:

PHP Code:

// set the current unix timestamp
define('TIMENOW'time()); 


Marco van Herwaarden 07-24-2007 08:56 AM

Working with a Unix timestamp is much easier in software. It is easier to sort or do calculations.

Also using TIMENOW instead of now() makes sure that you are using 1 timestamp for the whole execution of the script.

Eikinskjaldi 07-24-2007 10:03 AM

Quote:

Originally Posted by Marco van Herwaarden (Post 1299944)
Working with a Unix timestamp is much easier in software. It is easier to sort or do calculations.

Just have to agree to disagree on that one.

Within mysql, to turn a unixtime into a date time, use from_unixtime(val). To turn a datetime into a unixtime, use unix_timestamp(val). You can, for instance, do unix_timestamp(now())

And if you wanted to determine some date range from the timestamp, you can convert to datetime and then use the various mysql functions (which is why I think working with datetime is the preferred option) so for instance if you wanted all the posts from the last 14 days you could use

where to_days(now()) - to_days(from_unixtime(post.dateline)) <= 14.


All times are GMT. The time now is 06:23 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.00962 seconds
  • Memory Usage 1,726KB
  • 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
  • (1)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)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