Solved

date function

Posted on 2006-11-27
13
302 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now