PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > comparing unix_timestamp, converting to date
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comparing unix_timestamp, converting to date

Réponse
 
LinkBack Outils de la discussion
Vieux 09/04/2008, 21h06   #1
Sameer
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut comparing unix_timestamp, converting to date

Dear All,
I am a newbie to MySQL.
My table stores time in unix_timestamp type of column,
I can list it in date format using
from_unixtime(createdtime/1000,'%d-%m-%Y %H:%i:%S')

But how to compare it with dates?

createdtime is a field storing unix_timestamp then how can i retrieve
records having values greater that '01-Mar-08'? What are the related
functions?

Thanks in advance.

Regards,
Sameer


  Réponse avec citation
Vieux 09/04/2008, 22h26   #2
Michael Austin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: comparing unix_timestamp, converting to date

Sameer wrote:
> Dear All,
> I am a newbie to MySQL.
> My table stores time in unix_timestamp type of column,
> I can list it in date format using
> from_unixtime(createdtime/1000,'%d-%m-%Y %H:%i:%S')
>
> But how to compare it with dates?
>
> createdtime is a field storing unix_timestamp then how can i retrieve
> records having values greater that '01-Mar-08'? What are the related
> functions?
>
> Thanks in advance.
>
> Regards,
> Sameer
>
>



http://dev.mysql.com/doc/refman/5.0/...functions.html

This comes to mind - not tested.
datediff(from_unixtime(createdtime/1000,'%d-%m-%Y %H:%i:%S'),'1997-11-30
23:59:59')

from the docs:
"If you want to subtract UNIX_TIMESTAMP() columns, you might want to
cast the result to signed integers. See Section 11.9, “Cast Functions
and Operators”."

I tend to stay away from UNIX_TIME and use DATE field and NOW() for
those "audit-trail" type functions. Keep in mind that UNIX_TIME has
problems with dates prior to 1970 and certain timezones

see the docs
"Note: If you use UNIX_TIMESTAMP() and FROM_UNIXTIME() to convert
between TIMESTAMP values and Unix timestamp values, the conversion is
lousy because the mapping is not one-to-one in both directions. For
example, due to conventions for local time zone changes, it is possible
for two UNIX_TIMESTAMP() to map two TIMESTAMP values to the same Unix
timestamp value. FROM_UNIXTIME() will map that value back to only one of
the original TIMESTAMP values. Here is an example, using TIMESTAMP
values in the CET time zone"
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h44.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10750 seconds with 10 queries