Date and Time functions in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
php_kid
Forum Newbie
Posts: 1
Joined: Wed May 19, 2004 11:40 pm

Date and Time functions in php

Post by php_kid »

Hi All,
I am new to php.I am learning php now,can anyone give me solution for my following doubts,

1.I have a DateTime field in my table.It stores the currenty date/time to my table.Now i want to display it with yyyy/mm/dd format.

2.I have a timestamp(14) field in my table.What does it mean and how do i insert the current date/time.

Thanks,
php_kid
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

1. Look at MySQL's DATE_FORMATfunction:

2. Use the NOW() MySQL function.

Exp.:

Code: Select all

INSERT INTO table ( `timestamp_filed` ) VALUES ( NOW() )
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

Hi, welcome to PHPDN Forums.

1. You can get all information on the [php_man]date[/php_man]() function reference.

2. Assuming you're using MySQL, the Documentation covers TIMESTAMP column type on these links:Scorphus.
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

scorphus wrote:1. You can get all information on the [php_man]date[/php_man]() function reference.
Though, it would be easier to do it in SQL. I find that people get lazy, and leave everything to PHP when you can still do so much in SQL. I try to push the data formatting down as far as possible, so that when I get the result from the database, I don't have to deal with formatting it. I just get the result and start working with it.
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

Hello Jason,

Very good point. From time to time I see my weakness on MySQL. I always forget to let the work with it, an already compiled, linked, loaded and well written code. Thanks for the advice, and sorry for postposting your post.

Well, here is a direct link to the DATE_FORMAT() function reference.

Scorphus.
Post Reply