General [M]ayhem

Go Back   General [M]ayhem > Real Time Sub-Forums > CompuGlobalHyperMegaNet
Register Members List Mark Forums Read [M]erchandise Calendar

Reply
 
Thread Tools
_mike_
 
quick mysql question

this is a just for fun thing, but i figure someone knows. i have a column as a DATE type, which mysql said is for dates without times. when i do a select in my code, it's returning a time component, 0:00:00 GMT -500 EST.

why does it do that?


edit: it only does it in the website code (it's javascript), not when i query from mysql on the command line.
Old 01-17-2012, 05:08 PM _mike_ is offline  
Reply With Quote
#1  

Advertisement [Remove Advertisement]

Scatman
 
Scatman's Avatar
 
It's not supposed to. MySQL's DATE is just year, month and day. DATETIME is DATE plus a time component. Are you using PHP to connect to MySQL and casting it to a PHP date object?

Also Javascript's built-in Date object has both a date (year, month, day, day of week) and time components.

in chrome's console:
$ new Date().toString();
"Tue Jan 17 2012 20:50:20 GMT-0500 (EST)"
__________________
Code:[M]ayhem: Owned.
http://www.genmay.com/showthread.php?t=804869

"I'm gonna be rich and famous one day when I invent
a device that can be used to stab someone in the
face over the Internet."
Old 01-17-2012, 06:00 PM Scatman is offline  
Reply With Quote
#2  

Fiah
Sinds ik als transseksuele prostituee bezig ben, heb ik mezelf eindelijk leren accepteren. PM me voo
 
Fiah's Avatar
 
If you do the query in a test.php on your website and echo the result directly (no other stuff) as a string, no converting of any kind and no sending it over javascript, does it still give you the timezone stuff?

Mysqls DATE and DATETIME types do store the timezone afaik and do converting depending on what timezone the server is set to. However, it should always return a string like 2012-01-18, depending on the standard formatting settings. Or, you could specify your own:

SELECT DATE_FORMAT(`datecolumn`,GET_FORMAT(DATE,'USA')) FROM `myfirsttable`

The result should be '01.18.2012'
Old 01-17-2012, 10:04 PM Fiah is offline  
Reply With Quote
#3  

_mike_
 
ok. javascript was turning '2012-01-17' into a date object, which includes time. i just removed it.

thanks!
Old 01-18-2012, 01:29 PM _mike_ is offline  
Reply With Quote
#4  

Scatman
 
Scatman's Avatar
 
Quote:
Originally Posted by Fiah View Post
If you do the query in a test.php on your website and echo the result directly (no other stuff) as a string, no converting of any kind and no sending it over javascript, does it still give you the timezone stuff?

Mysqls DATE and DATETIME types do store the timezone afaik and do converting depending on what timezone the server is set to. However, it should always return a string like 2012-01-18, depending on the standard formatting settings. Or, you could specify your own:

SELECT DATE_FORMAT(`datecolumn`,GET_FORMAT(DATE,'USA')) FROM `myfirsttable`

The result should be '01.18.2012'
<-- pwnt.
It's been years since I've touched MySQL.
__________________
Code:[M]ayhem: Owned.
http://www.genmay.com/showthread.php?t=804869

"I'm gonna be rich and famous one day when I invent
a device that can be used to stab someone in the
face over the Internet."
Old 01-18-2012, 03:14 PM Scatman is offline  
Reply With Quote
#5  

_mike_
 
Quote:
Originally Posted by Scatman View Post
<-- pwnt.
It's been years since I've touched MySQL.

dude, you gave me the answer .

p.s. this is node.js, not php.
Old 01-18-2012, 04:36 PM _mike_ is offline  
Reply With Quote
#6  

Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -7. The time now is 08:01 AM.



Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.