Solved

date function

Posted on 2006-11-27
13
304 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

776 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