Skip to Content
It is currently October 24th, 2019, 12:01 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: How change date format?
PostPosted: September 23rd, 2019, 4:59 pm 
Offline
Senior User
Senior User

Joined: July 23rd, 2007, 2:22 am
Posts: 117
Hello out there all you SAM Broadcasters! I have a question that might be related to the SAM config.php file or an SQL issue. I've just begun displaying the Date Added and Last Played dates on my songs and they currently display like this:

Code:
Times played: 1 / Times requested: 0 / Genre: Other African / Year: 1996
Date Added: 2019-09-10 19:12:43 / Last played: 2019-09-23 14:54:02


I want to change the date format to something like:

Code:
Tue Sep 23 2019 2:54 PM


Could someone tell me how to do this?

Thanks!
Dan

_________________
Park Magic Radio
http://parkmagicradio.ca


Top
 Profile  
Reply with quote  
PostPosted: September 25th, 2019, 10:42 am 
Offline
SVS Member
SVS Member

Joined: May 8th, 2004, 9:00 am
Posts: 10449
Location: Denver, CO
Display where? on your web page? If so, provide the relevant code used to display the date you are using.

_________________
- Rob Oyler, SVS
Image


Top
 Profile  
Reply with quote  
PostPosted: September 25th, 2019, 12:54 pm 
Offline
Senior User
Senior User

Joined: July 23rd, 2007, 2:22 am
Posts: 117
Yes. I'm not looking on HOW to change it, I'm looking at WHERE to change it, if you know. I know how to change it and what format I want, but I'm having a problem trying to locate the file I can change it in. I'm sorry I wasn't more specific.

_________________
Park Magic Radio
http://parkmagicradio.ca


Top
 Profile  
Reply with quote  
PostPosted: September 26th, 2019, 3:15 pm 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 7878
Location: Aachen (Germany)
Convert the MySQL Timestamp string into a PHP timestamp/unix timestamp and then format it using date.
How to:
  1. $php_timestamp = strtotime($mysql_timestamp);
  2. $rfc2822_timestamp = date('r', $php_timestamp);

RFC2822 might not be exactly what you want, but it was the easiest to type for an example ;)
You can put together any format string you like using as many or few of the placeholder letters as you like. Any symbol/character that is not specified to be a placeholder will be printed literally (i.e.: date('xxxh') will print xxx10 (Current Time in Germany is 22:13, h is placeholder for the hour in 12 hour format with leading zero)

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

We're offering custom PAL / PHP code and general SAM assistance at palscripts.com

My Project:
Send "Now Playing" from SAM to Twitter and/or Facebook | Sourcecode


Top
 Profile  
Reply with quote  
PostPosted: September 27th, 2019, 12:48 pm 
Offline
Senior User
Senior User

Joined: July 23rd, 2007, 2:22 am
Posts: 117
Mastacheata wrote:
Convert the MySQL Timestamp string into a PHP timestamp/unix timestamp and then format it using date.


Thanks!

I know how to display the time but can't get it to say anything other than Wed, Dec 31, 1970 - 04:16:00 PM - it says this for every song. I tried playing a song that's been played more than once and it still says the same thing.

I'm not sure how this command gets the last played time from the currently playing track.

_________________
Park Magic Radio
http://parkmagicradio.ca


Top
 Profile  
Reply with quote  
PostPosted: September 28th, 2019, 9:08 am 
Offline
SVS Member
SVS Member

Joined: May 8th, 2004, 9:00 am
Posts: 10449
Location: Denver, CO
dan40 wrote:
Mastacheata wrote:
Convert the MySQL Timestamp string into a PHP timestamp/unix timestamp and then format it using date.


Thanks!

I'm not sure how this command gets the last played time from the currently playing track.
here you go:
Code:
//Select Date Last played
  $result = mysqli_query( $samDB, "SELECT date_played FROM historylist where songID in ( " . $now_playing["song_id"] . " ) Order by date_played DESC Limit 2 offset 1" );
  $last_played = mysqli_fetch_array( $result );

In the Config:
Code:
class Configuration
{
      public $date_time_format             = "D M d, Y g:i a";
}

Display it:
Code:
                 <tr>
                    <td align=right nowrap><b>Last Played:</b></td>
                    <td>&nbsp;&nbsp;</td>
                    <td align=left><?php echo( date( $configuration->date_time_format, strtotime( $last_played["date_played"] ) ) ); ?></td>
                  </tr>

_________________
- Rob Oyler, SVS
Image


Top
 Profile  
Reply with quote  
PostPosted: October 2nd, 2019, 1:51 am 
Offline
Senior User
Senior User

Joined: July 23rd, 2007, 2:22 am
Posts: 117
Thank you!

I put this in class.song.php:

Code:
class Configuration
{
      public $date_time_format             = "D M d, Y g:i a";
}


And I put this in display.playing.php:

Code:
                 <tr>
                    <td align=right nowrap><b>Last Played:</b></td>
                    <td>&nbsp;&nbsp;</td>
                    <td align=left><?php echo( date( $configuration->date_time_format, strtotime( $last_played["date_played"] ) ) ); ?></td>
                  </tr>


But am not sure where to put this. I had it in a couple of different places, and changed a bit of the code but it ended up displaying December 31, 1969 again:

Code:
//Select Date Last played
  $result = mysqli_query( $samDB, "SELECT date_played FROM historylist where songID in ( " . $now_playing["song_id"] . " ) Order by date_played DESC Limit 2 offset 1" );
  $last_played = mysqli_fetch_array( $result );


It looks very promising! If I could just get past this then I'm sure it would work!

_________________
Park Magic Radio
http://parkmagicradio.ca


Top
 Profile  
Reply with quote  
PostPosted: October 2nd, 2019, 6:48 pm 
Offline
SVS Member
SVS Member

Joined: May 8th, 2004, 9:00 am
Posts: 10449
Location: Denver, CO
If you are trying to use the last section of code I provided, it will not work with the standard SAM template do to the fact $samDB is undefined and so is $now_playing. You would need to use the pdo used in the template to retrieve the data need and display it. I don't work with the templates so I can't offer a final solution.

_________________
- Rob Oyler, SVS
Image


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: MSN [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group