Solved

date function

Posted on 2006-11-27
13
305 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:FLAASHER
  • 5
  • 4
  • 2
  • +1
13 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 18021236
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
 
LVL 13

Author Comment

by:FLAASHER
ID: 18021423
really i cant deal with it :(

can u please give me an example ??


many thanks



FLAASHER
0
 

Expert Comment

by:mingle75
ID: 18021978
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 49

Expert Comment

by:Roonaan
ID: 18022019
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
 
LVL 13

Author Comment

by:FLAASHER
ID: 18022376
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
 

Expert Comment

by:mingle75
ID: 18023619
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
 
LVL 1

Accepted Solution

by:
dr-dre67 earned 500 total points
ID: 18060751
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
 
LVL 13

Author Comment

by:FLAASHER
ID: 18060845
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
 
LVL 1

Expert Comment

by:dr-dre67
ID: 18100717
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
 
LVL 13

Author Comment

by:FLAASHER
ID: 18100775
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
 
LVL 1

Expert Comment

by:dr-dre67
ID: 18111444
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
 
LVL 1

Expert Comment

by:dr-dre67
ID: 18111451
and i should get my 500 points because your first question is repied ;)

0
 
LVL 13

Author Comment

by:FLAASHER
ID: 18112209
yes u should  ..... :)

many thanks

Flaasher
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What does this formatting equate to? 7 18
parse url to form? 7 25
PHP Echo with auto submit 8 30
PHP alternative to file_get_contents('php://input') 4 74
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question