date function

Hello experts

i use date function like this  .........


<?
echo date ("l dS of F Y h:i:s A");
?>


this code print = Monday 27th of November 2006 09:11:06 PM


iam asking how can i catch "Monday" and "November"  to replace it with other words of my native language using case statment


Thanks all


FLAASHER
LVL 13
FLAASHERAsked:
Who is Participating?
 
dr-dre67Connect With a Mentor Commented:
Hello

$thedate =  date ("l dS of F Y h:i:s A");  

$adate = explode(" ",$thedate);
$day_name = $adate[0];
$month_name = $adate[3];

switch($day_name){
case 'Saturday';
$new_day = "ÇáÓÈÊ";
break;
case 'Sunday';
$new_day = "ÇáÃÍÏ";
break;

}
switch($month_name){
case 'November';
$new_month = "äæÝãÈÑ";
break;
case 'December';
$new_month = "ÏíÓãÈÑ";
break;


}

$NEW_DATE = date("$new_day dS of $new_month Y h:i:s A");
echo $NEW_DATE;

i think this is the solution to parse the month and the day with explode and make a switch and case condition

Hachem LATRACH
0
 
RoonaanCommented:
Then you would have to use:

setlocale(LC_DATE, "nl_NL"); //change to your locale,

and instead of date, use strftime() (see php.net/strftime)

-r-
0
 
FLAASHERAuthor Commented:
really i cant deal with it :(

can u please give me an example ??


many thanks



FLAASHER
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
mingle75Commented:
Try the getdate() function.  It returns an array that contains date and time information - ten elements with relevant information needed when formatting a date string.

[seconds] - seconds
[minutes] - minutes
[hours] - hours
[mday] - day of the month
[wday] - day of the week
[year] - year
[yday] - day of the year
[weekday] - name of the weekday
[month] - name of the month

http://www.w3schools.com/php/func_date_getdate.asp

You can build your case statement selecting [weekday] and [month] elements of array and replace them with appropriate strings from your native language.

0
 
RoonaanCommented:
The setlocale you have to find out yourself, or tell us which language you need. For strftime you can use:

echo strftime('%A %e %B %Y %T %p');

-r-
0
 
FLAASHERAuthor Commented:
my problem is that  i have "ARABIC" site ..... this site ruturn new from data base ..... each record from news has a date in this format "22-12-2006"


the problem is the client want it like this

Monday 27th of November 2006 09:11:06 PM



how can i do this ??




FLAASHER
0
 
mingle75Commented:
Will this work for you?

<?php
//parse the news date
$news_date = "22-12-2006";

//get month
$m = substr($news_date, 0, 2);

//get day of month
$d = substr($news_date, 3, 2);

//get year
$y = substr($news_date, 6, 4);

//the mktime() function returns the Unix timestamp for a specified date.
//Syntax
//mktime(hour,minute,second,month,day,year,is_dst)

$unix_date = mktime(0,0,0,$m,$d,$y);

//Syntax
//getdate(timestamp)
//Parameter Description
//timestamp Optional. Specifies the time in Unix time format

$my_date=getdate($unix_date);

print("$my_date[weekday] $my_date[mday]th of $my_date[month] $my_date[year] $my_date[hours]:$my_date[minutes]:$my_date[seconds] PM");

?>

You will not be able to supply a time stamp if your input is only "22-12-2006" but you will be able to retreive the day of the week and month.  You will have to write some additional code to conditionally place "th" or "rd" at the end of the day of the month as appropriate.
0
 
FLAASHERAuthor Commented:
hello dr-dre67


Thanks for the solution ... its the best solution

iam aking if i can send u an email with example to check please ???


just wanna ask ....



 i have it stored in the data base in this format >>>>>   "22-12-2006"


the problem is the client want it like the folowing format in arabic :

Monday 27th of November 2006 09:11:06 PM


u Give me a nice solution and it fine :)


but what can i do if i have it in this format "22/11/2006"  NOT this format "Monday 27th of November 2006 09:11:06 PM"
 is it possible to make the same solution in this case ???


another point :) ......

is it possible to compare more than one date in this format ""Monday 27th of November 2006 09:11:06 PM"" ????
i mean i have many news and each one with date like this "Monday 27th of November 2006 09:11:06 PM" ..... how can i know the oldest one or newest one ??




many thanks for ur help




FLAASHER
 



0
 
dr-dre67Commented:
Hello ,

You can make the same method by changing the variables in switch / case

for descending the data from database by oldest , u say that ur table contain news

so the table have an increment field ( ID )

so u can descend it by id


ORDER BY ID DESC

that order the data by NEWEST

ORDER BY ID ASC

that order the data by olders

:)

Hachem LATRACH
0
 
FLAASHERAuthor Commented:
i know this case
but what i want do to is to see if any new is 10 days ago or more i will write beside it "Old" ...... if it less than 10 days i will write "NEW" .... how to make this ???


FLAASHER
0
 
dr-dre67Commented:
so u need to add the date field as time()


and compare the diffirence


for exemple

$date = time() // the now time when u add the article or anything to be added to DB

// u will insert the fields to db ( $date in field called date_entry for exampl )
$DBADDED = mysql_query("INSERT ..... ");
...

and when showing article
show him by id
and just make a condition for the time() - date_entry if he is equal of  864000 for each article  ( the number of secndes in 10 days )

if u like i can explain by code :)



HACHEM LATRACH

0
 
dr-dre67Commented:
and i should get my 500 points because your first question is repied ;)

0
 
FLAASHERAuthor Commented:
yes u should  ..... :)

many thanks

Flaasher
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.