Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

date function

Posted on 2006-11-27
13
Medium Priority
?
309 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Tutorial: Introduction to Managing a Linux Server

In this tutorial on systemd, we will explore:
-OS/Distro Adoption
-chkconfig and Other Legacy Commands
-Summary and Key Commands

 
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 2000 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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 a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

730 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