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?
Date
Moderator: General Moderators
Code: Select all
$date=date("FdY");-
Cruzado_Mainfrm
- Forum Contributor
- Posts: 346
- Joined: Sun Jun 15, 2003 11:22 pm
- Location: Miami, FL
try using another kind of field, check this:
if you see that the field `timedate` is INT is because you can insert the date in Unix format, like this:
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
check out [php_man]date()[/php_man]
Code: Select all
CREATE TABLE `table1` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`timedate` INT UNSIGNED NOT NULL ,
INDEX ( `id` )
);Code: Select all
INSERT INTO ab (id,timedate) VALUES ("",UNIX_TIMESTAMP());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
}
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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:
Mac
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;
?>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
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