Webmaster Key - Discussion Forums


Welcome, Guest. Please login or register.
Did you miss your activation email?
February 09, 2012, 06:54:23 AM

Login with username, password and session length
Welceome to Forums!

Important information for guests and new members:

In order to understand the full benefits of becoming an active member of this forum, please review the following information on guest and new member restrictions. These forum changes have been prompted by an overwhelming and unreasonable amount of bot postings and incoherent guest spam messages. We wish to prevent these events from happening in the future and make our community a more comfortable place for all of our members.

For guests:

Guests are not allowed to open new topics, polls, or posts attachments.
If you wish to open up new discussions on this forum, we encourage you to register.

For new members:

New members with less than five posts are not allowed to modify additional profile information such as avatars, contact information, biographies, and signatures. However, new members are encouraged to post their own topics or reply to topics initiated by other members. Become active on the forums and 5 posts should be an easy task!

We are a diverse community with members from all over the world. We encourage new ideas and interesting conversation. Do not be afraid to post webmaster/computer-related questions or problems, as our active members are always willing to help when they are able. Interested? Join us.

+ Webmaster Key Forums
|-+ Webmaster Corner
| |-+ Site Design and Web Authoring
| | |-+ Coding Talk
| | | |-+ A php- mysql problem- date formats problem
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Go Down Stumble Upon! Digg It! del.icio.us! Add to Technorati! ReddIt!  Send this topic Print
Author Topic: A php- mysql problem- date formats problem  (Read 2685 times)
Aji
Key Keeper
Member
**
Posts: 64



« on: May 22, 2004, 07:51:24 AM »

Hi all,

I have a simple problem, I tried it but getting error, still trying to solve but thought will get the help from some experts too.

Database(mysql) date format :yyyy-mm-dd 00:00:00
client site query date is : dd/mm/yyyy

I have seprated the client side date into different portions like (dd) and (mm) and (yyyy). I can get them

My problems
------------------
(1) I want to query between two dates say 21/04/2004 to 23/04/2004 , how to do that ??
(2) I want yyyy-mm-dd 00:00:00 , to seprate month , date , year , time from this format using php, how can I do that, I know its easy but I am not an expert on php and mysql.

I am using the following query, but the problem is with the date format ,
$sql1="select * from TblUsers1,TblUserInfo1 where TblUserInfo1.FldUserID=TblUsers1.FldUserID and (TblUsers1.FldDateSubscribed BETWEEN '$StartDate' AND '$EndDate')";


HELP HELP HELP

Thank you
Aji
Report to moderator   Logged

Hedir.com - Human Edited Directory of 2006 - Submit your site
Nigritude Ultramarine - Nigritude Ultramarine competitions, Nigritude Ultramarine logo
Andy
Administrator
Veteran
*****
Posts: 5 752



« Reply #1 on: May 22, 2004, 08:09:19 PM »

Hi Aji,

It seems like your main problem is how to translate from dd/mm/yyyy to yyyy-mm-dd 00:00:00

Since you already seperated out the dd mm yyy bits, it should be easy.

What I suspect you should study is the sprintf function which is copied from the C programming language. The other one is printf (for printing to a printer). These functions let you insert data into a string very easily.

<url>http://www.php.net/manual/en/function.sprintf.php</url>
Report to moderator   Logged

lostingermany
Key Keeper
Jr. Member
*
Posts: 27


« Reply #2 on: May 23, 2004, 03:19:11 PM »

Hi Aji

It sounds like the structure of your table column is wrong. If you use date instead of datetime() for your column type all you will have is the date and not the linux time stamp.
Then the next thing to do is to put the date string together from the input. You can do that like this:

If you use post:

$startdate = $_POST['startyear']."-".$_POST['startmonth']."-".$_POST['startday'];
$enddate = $_POST['endyear']."-".$_POST['endmonth']."-".$_POST['endday'];

If you use get:
$startdate = $_GET['startyear']."-".$_GET['startmonth']."-".$_GET['startday'];
$enddate = $_GET['endyear']."-".$_GET['endmonth']."-".$_GET['endday'];

Now you can use these variables in your SQL query.

$sql1="select * from TblUsers1,TblUserInfo1 where TblUserInfo1.FldUserID=TblUsers1.FldUserID and (TblUsers1.FldDateSubscribed BETWEEN '$startdate' AND '$enddate')";

Have fun with it

lostingermany
Report to moderator   Logged
Pages: [1] Go Up Stumble Upon! Digg It! del.icio.us! Add to Technorati! ReddIt!  Send this topic Print 
+ Webmaster Key Forums
|-+ Webmaster Corner
| |-+ Site Design and Web Authoring
| | |-+ Coding Talk
| | | |-+ A php- mysql problem- date formats problem

Jump to:  
« previous next »


Our Partners
RelmaxTOP Ranking System Web Hosting RelmaxTOP Ranking System
Staff Sites
12Noon[12Noon Gallery] Andy[Urgentclick]
Tamuril[Tamuril's Digital Art Exhibit] Sensovision
Powered by MySQL Powered by PHP We are hosted by Relmax Inc. |Our Privacy Policy | Sitemap
Powered by SMF 1.1.9 | SMF © 2006-2009, Simple Machines LLC
Forum design by Tamuril © 2005.
Valid XHTML 1.0! Valid CSS!