Date

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
lapicki
Forum Newbie
Posts: 11
Joined: Sun Mar 16, 2003 4:03 pm

Date

Post by lapicki »

I have a table in mssql7.0 and a field defined as datetime

Desire that a date is printed like day, month, year

but it leaves the following way

Feb 24 2004 12:00AM

since I make to eliminate the hour?
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Code: Select all

$date=date("FdY");
That will do the month / day / year thing if you mean that ?!
lapicki
Forum Newbie
Posts: 11
Joined: Sun Mar 16, 2003 4:03 pm

Post by lapicki »

it does not change anything, continues showing

Feb 25 2004 12:00AM

I need that it does not show the hour
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

try using another kind of field, check this:

Code: Select all

CREATE TABLE `table1` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`timedate` INT UNSIGNED NOT NULL ,
INDEX ( `id` ) 
);
if you see that the field `timedate` is INT is because you can insert the date in Unix format, like this:

Code: Select all

INSERT INTO ab (id,timedate) VALUES ("",UNIX_TIMESTAMP());
Note: If no parameter is set in the function, it will return the time and date of that moment, of course it's an integer in case you get confused, it will be a bunch of numbers, which are actually the numbers of seconds elapsed from some date that i forgot but anyways that's what it is

check that i used the function UNIX_TIMESTAMP() where the date is entered..., now to get the date from the table u can do this

Code: Select all

<?php
mysql_connect();
$query = "select timestamp from database1.table1";
$result = mysql_query($query);
while ($array = mysql_fetch_array($result,MYSQL_ASSOC)) {
echo date('l dS of F Y h:i:s A',$array['timestamp']).'<br />'; //you should change the first parameter of the date function
}
?>
check out [php_man]date()[/php_man]
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Cruzado_Mainfrm - always a good idea to read the question carefully, note where it says that the user is using mssql 7.0 not MySQL.

lapicki - does MSSQL have functions for formatting the date when it is extracted from the database, I would assume it does and that's what you should use before PHP's date and time functions.

However, if you are unable to format the date in your SELECT statement you could use [php_man]strtotime[/php_man]() to format your date into a timestamp and then use date() as previously suggested:

Code: Select all

<?php

$date_from_db = 'Feb 24 2004 12:00AM';
$date_timestamp = strtotime($date_from_db);
$date_formatted = date('d/m/Y', $date_timestamp);

echo $date_formatted;

?>
Mac
lapicki
Forum Newbie
Posts: 11
Joined: Sun Mar 16, 2003 4:03 pm

Post by lapicki »

I already solved east problem, thanks
I have left to solve like recording a data dates in the table sql
The program receives date data but it records them like 01/01/1900


MSSQL_CONNECT($hostname,$username,$password) or DIE("DATABASE NO RESPONDE");
MSSQL_SELECT_DB(cgba) or DIE("DATABASE NOT SELECTED");

$result=MSSQL_QUERY("Update Intranet Set FechaEntrega = $fechaentrega1 where Clave = 2");
$result=MSSQL_QUERY("Update Intranet Set FechaEntrega = $fechaentrega2 where Clave = 3");

mssql_close;

As I give to format from date to the field $fechaentrega1, 2, etc,

excuse by my ingles
Post Reply