MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old June 30th, 2003, 01:00 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
mysql datetime + mktime();

ok,....I am using a datetime field in mysql so that I can do date comparisons via sql syntax.

however, when I try to pass that mysql field to date(); I get.

Wed, December 31, 1969 @ 7 pm


so,....I pass my mysql field into mktime()

PHP Code:
 $date mktimemysql_row['datetime_field'] ); 


then my date displays correctly.



now the question...lol
I like storing my dates as datetime fields so I can compare via sql, but this extra step through mktime(); is killing me. is there another way to do this?
__________________
-- Jason

Reply With Quote
  #2  
Old June 30th, 2003, 01:13 PM
neoxean neoxean is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 5 neoxean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Not that I know of. Is this really such a big deal? You write the code once in a function and you never have to look at it again.

Reply With Quote
  #3  
Old June 30th, 2003, 03:10 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
well for large queries it can be,.... I mean,...I am doing 1 comparison in sql, then have to pass it through mktime();,....so,...yes and no i guess,....just looking for options is all

Reply With Quote
  #4  
Old June 30th, 2003, 03:47 PM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
You will find that for many reasons you will have to convert your date. I won't go into detail right now as the subject can get quite complex, but just know that this is the case.

Its really not that intese to run a function over your date field, and there really isn't a "better" way to do it IMHO; however, if you want you to can use the database function: UNIX_TIMESTAMP().

This is a mysql function, so do expect that it is portable to another DB Engine. Its possible, but not likely. Just make sure you test across ports before use.
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Last edited by laidbak : June 30th, 2003 at 03:50 PM.

Reply With Quote
  #5  
Old June 30th, 2003, 04:39 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
gotcha,....ohh and I got that date time select class working great now. POST info stays saved in the form in case of errors as well

Reply With Quote
  #6  
Old June 30th, 2003, 05:18 PM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
Cool... post an example.

Reply With Quote
  #7  
Old June 30th, 2003, 11:25 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
there is not much different then the previous, there are a few changes though. an if else statement is in there in case the form has been posted. just posting 1 of the functions here.

PHP Code:
class dateSelect
{
    function 
sMonth$sMonth$cssid$name )
    {
        echo 
"<select class=\"$cssid\" name=\"$name\">";
        if( 
$sMonth )
        {
            for( 
$i 1$i 13$i++ )
            {
                if( 
$i == $sMonth )
                {
                    echo 
"<option value=\"$i\" selected=\"selected\">";
                }
                else
                {
                    echo 
"<option value=\"$i\">";
                }
                echo 
date"F"mktime0,0,0,$i,1,date"Y" ) ) ) . "\n";
            }
        }
        else
        {
            for( 
$i 1$i 13$i++ )
            {
                if( 
$i == date"n" ) )
                {
                    echo 
"<option value=\"$i\" selected=\"selected\">";
                }
                else
                {
                    echo 
"<option value=\"$i\">";
                }
                echo 
date"F"mktime0,0,0,$i,1,date"Y" ) ) ) . "\n";
            }
        }
        echo 
"</select>&nbsp;";
    }



usage
PHP Code:
 $myDate = new dateSelect;
$myDate->sMonth( @$_POST['sMonth'], 'css_class''sMonth' ); 

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > mysql datetime + mktime();


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway