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 08-27-2004, 12:30 AM date function in PHP
zscherween's Avatar
Skilled Talker

Posts: 66
Location: Makati, Philippines
Trades: 0
Hy everyone!

Is there a function in PHP for dates? specifically just like DateAdd in VB6?

eg. to get the date 3 days from 2/28/04 (wich is 3/2/04) i would just do DateAdd("d",3,"2/28/04"). Is there a similar function or way to do it on PHP?

Thanks in advance,
Sherwin
__________________

Please login or register to view this content. Registration is FREE
- Get your Noynoy shirts here
zscherween is offline
Reply With Quote
View Public Profile Visit zscherween's homepage!
 
 
Register now for full access!
Old 08-27-2004, 12:50 AM
Unknown.

Posts: 1,693
Trades: 0
Yea... use the date function...

Check out...

http://uk.php.net/manual/en/function.date.php

That should help

--James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 08-27-2004, 01:03 AM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
To mimick the DateAdd function, you'll want to work with a timestamp. A timestamp is just the number of seconds since the UNIX epoch (Jan 1, 1970). So, for example, to add three days to the current date, just add the number of seconds in three days to the current timestamp:
PHP Code:
$timestamp time() + (60 60  24 3); 
That is the hard way, I thought I'd explain that so you know how timestamps work

The mktime() function allows you to specify a specific time through the list of it's arguments. You can use the date() function combined with the mktime function to achieve the same as we did above:
PHP Code:
$timestamp mktime(000date('m'), date('d') + 3); 
Once you have your timestamp, you can pass it to the date function with whatever format string you want.
PHP Code:
echo date('m.d.y'$timestamp); 
Hope that helps!
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 08-27-2004, 01:21 AM
zscherween's Avatar
Skilled Talker

Posts: 66
Location: Makati, Philippines
Trades: 0
great! thanks guys!

Does it also work on days before 1/1/1970?
__________________

Please login or register to view this content. Registration is FREE
- Get your Noynoy shirts here
zscherween is offline
Reply With Quote
View Public Profile Visit zscherween's homepage!
 
Old 08-27-2004, 01:55 AM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
That would be a negative timestamp, and if you read the page on mktime():
Quote:
Windows: Negative timestamps are not supported under any known version of Windows. Therefore the range of valid years includes only 1970 through 2038.
So they work fine on *nix machines. But who needs dates before 1970?
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to date function in PHP
 

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.23298 seconds with 12 queries