Welcome Guest, Not a member yet? Register   Sign In
Need help in getting date time with am pm
#1

[eluser]Mistry007[/eluser]
Hi every one. I have got one problem. which is as follow
I have converted date to my local time as below
Code:
$this->date_string = "%Y/%m/%d %h:%i:%s";
  $timestamp = now();
  $timezone = 'UP45';
  $daylight_saving = TRUE;
  $time =  gmt_to_local($timestamp, $timezone, $daylight_saving);
$this->updated_date = mdate($this->date_string,$time);

And Storing this field in to database.

now at retrive time i want like this format
Code:
"11-04-2011 4:50:00 PM"
I have used this code
Code:
$timestamp = strtotime($rs->updated_date);
$date1 = "%d-%m-%Y %h:%i:%s %a";
$updat1 = date($date1,$timestamp);
but this will give me only
Code:
"11-04-2011 4:50:00 AM"
but I have stored in like it was PM.
Can any one help me out.
thanks.


#2

[eluser]zoopstud[/eluser]
Code:
$this->date_string = "%Y/%m/%d %h:%i:%s";

Your missed the %a, also if you want AM PM it needs to be a capital A

Code:
$this->date_string = "%Y/%m/%d %h:%i:%s %A";

Think the default is am.
#3

[eluser]Mistry007[/eluser]
Hi thanks for help.
Actually i have missed something else to.
that is
Code:
$this->date_string = "%Y/%m/%d %h:%i:%s";
  $timestamp = now();
  $timezone = 'UP45';
  $daylight_saving = TRUE;
  $time =  gmt_to_local($timestamp, $timezone, $daylight_saving);
$this->updated_date = mdate($this->date_string,$time);

In this code i have converted the format string in 12 hours format. that was my mistake.
now i have sloved this.
Code:
$this->date_string = "%Y/%m/%d %H:%i:%s";
  $timestamp = now();
  $timezone = 'UP45';
  $daylight_saving = TRUE;
  $time =  gmt_to_local($timestamp, $timezone, $daylight_saving);
$this->updated_date = mdate($this->date_string,$time);


Now using this I have sloved this problem.
thanks for this help.
I have used "%A" now and its working fine now.
Thanks a lot.




Theme © iAndrew 2016 - Forum software by © MyBB