Current location: Hot Scripts Forums » Programming Languages » PHP » Convert Date


Convert Date

Reply
  #1 (permalink)  
Old 01-01-08, 09:16 AM
Nikas Nikas is offline
Coding Addict
 
Join Date: Jun 2005
Location: Singapore
Posts: 377
Thanks: 0
Thanked 1 Time in 1 Post
Convert Date

Hi all,

I have stored unix timestamp in my database. I wanted to do a query to select date between months.

This is my query to convert the time from unix to normal timestamp

PHP Code:

$Q $db->query("SELECT opened FROM phpdesk_tickets");

        while (
$F $db->fetch($Q)) {
            
$dateconvert date('Y-m-d'$F['opened']);
            echo 
"<br>".$F['opened']." // ".$dateconvert; } 
This is the result

PHP Code:

1190477670 // 2007-09-22

1190486212 // 2007-09-22
1190486393 // 2007-09-22
1190486415 // 2007-09-22
1190486526 // 2007-09-22
1190486622 // 2007-09-22
1190645584 // 2007-09-24
1191047338 // 2007-09-29
1192166236 // 2007-10-12
1192166750 // 2007-10-12
1199038391 // 2007-12-30
1199038276 // 2007-12-30
1199038061 // 2007-12-30
1199038435 // 2007-12-30
1199038555 // 2007-12-30
1199038761 // 2007-12-30
1199039346 // 2007-12-30
1199039530 // 2007-12-30
1199039736 // 2007-12-30
1199039863 // 2007-12-30
1199041151 // 2007-12-30
1199041224 // 2007-12-30 
But I'm not sure how can I do a query to select between months.
Any one can guide me through?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 01-01-08, 09:22 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
sql Code:
  1. SELECT * FROM `phpdesk_tickets` WHERE `opened` BETWEEN timestamp1 AND timestamp2

If you need to convert a date to timestamp, use strtotime() or mktime().
Reply With Quote
  #3 (permalink)  
Old 01-01-08, 10:19 AM
Nikas Nikas is offline
Coding Addict
 
Join Date: Jun 2005
Location: Singapore
Posts: 377
Thanks: 0
Thanked 1 Time in 1 Post
Thanks. I think what I need is strtotime()
Reply With Quote
  #4 (permalink)  
Old 01-01-08, 10:38 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
If your date was stored in the database using a mysql DATE or DATETIME data type, there are several msyql functions that would let you compare and select the dates you want directly in your query, without any need to convert values.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #5 (permalink)  
Old 01-01-08, 11:07 AM
Nikas Nikas is offline
Coding Addict
 
Join Date: Jun 2005
Location: Singapore
Posts: 377
Thanks: 0
Thanked 1 Time in 1 Post
Yes, mab.

I'm currently working on a open source, and the date stored is in unix time, as I don't wish to mess things up. I'm converting the time instead of using DATETIME data type.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
converting date-string to Date object UnrealEd Everything Java 4 05-15-07 06:20 PM
Want to bring your website up to date? Convert to AJAX! Anastas Job Offers & Assistance 7 08-22-06 04:13 AM
Convert timestamp to date with Date::Manip FiRe Perl 1 07-29-05 05:54 AM
date problem - convert eg. '06' to 'jun' tallpaul858 PHP 3 04-16-05 06:39 PM
convert a date into an int Deadlock PHP 1 12-07-04 04:41 AM


All times are GMT -5. The time now is 07:33 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.