Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 04-03-2005, 11:45 AM Date Problem
merlin's Avatar
Skilled Talker

Posts: 52
Trades: 0
Hello,

I would like to have a form with a hard coded date. I have set the date parameter as.....

PHP Code:
$today date("F j, Y"); // Format example = March 10, 2001 
My problem is how to I get it to submit into a field on a MySQL database I have named "General Date". Furthermore how would I code for a search to list say only the Month or day or best yet a string between say March 10 and March 17, for an example.

This seems to be pretty high level stuff and I wouldn't be so any help anyone could offer would be great.


merlin is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-03-2005, 07:14 PM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
Quote:
My problem is how to I get it to submit into a field on a MySQL database I have named "General Date".
ok dude, this is gonna be quick and maybe painful, i wanna go to bed and I'm ill! But i had the same problem once too (i'm sure we all did)

First off, you don't have to enter a certain date into SQL if it's the same date as today, you can simply put CURDATE( ). If it's not todays date, then SQL demands you have the date in an american way (so YEAR-MON-DAY or YYYY-MM-DD).

So, if you want to convert a date into the SQL format, we can do this:


PHP Code:
/* Note: gmdate = the date at GMT (i.e. England)
    Note: Y = 4 digit year, m= numerical month, with 0s, d= numerical day, with 0s
    Note: month, day, year should be replaced with the month, day, year you wish to be
changed into the SQL format, these should be in NUMERICAL form. */

$SQLDate gmdate("Y-m-d"mktime(000monthdayyear)); 
So, therefore, it makes sense that to change a date FROM SQL format to whatever desired format you need, we do this:

PHP Code:
/* new addition here is the list and split, this will split the SQL style YYYY-MM-DD into three
variables: $year, $month, $day. The only variable you need to define is $date, which 
would be the SQL date, from the database. */

list($year$month$day) = split('[/.-]'$date);

$NiceDate gmdate("d F Y"mktime(000$month$day$year));

/* This outputs something like: 04 April 2005 i believe */ 
As for:
Quote:
Furthermore how would I code for a search to list say only the Month or day or best yet a string between say March 10 and March 17, for an example.
Well, SQL has it's own QUERY details that can help here, search for some article about them, it will be faster than using PHP and a **** of a lot easier!

Hope this helps, please write back!
leavethisplace is offline
Reply With Quote
View Public Profile
 
Old 04-03-2005, 09:18 PM
merlin's Avatar
Skilled Talker

Posts: 52
Trades: 0
Thanks bud, I'll give it a try and let you know. Thanks again
merlin is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Date Problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12633 seconds with 12 queries