Page 1 of 1
Date
Posted: Tue Feb 10, 2004 11:41 am
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?
Posted: Tue Feb 10, 2004 12:34 pm
by ol4pr0
That will do the month / day / year thing if you mean that ?!
Posted: Tue Feb 10, 2004 1:13 pm
by lapicki
it does not change anything, continues showing
Feb 25 2004 12:00AM
I need that it does not show the hour
Posted: Tue Feb 10, 2004 2:14 pm
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]
Posted: Wed Feb 11, 2004 4:03 am
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
Posted: Wed Feb 11, 2004 7:59 am
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