Skip to Content Skip to Menu

string to date field

13 years 4 weeks ago #177351 by busterocaps
string to date field was created by busterocaps
Hi,
I've tried everything I can think of to get this to work, but no go. No one seems to have posted this on the forum either. What I'm doing is trying to update a user value on profile view.

switch($tid)
{
case $data->{recent_games}[1]->tid:
//$resultDate = strtotime($data->{recent_games}[1]->last_played);
$user->cb_lastactive = $data->{recent_games}[1]->last_played;
$user->store();
$user->cb_lastplayeddate = $data->{recent_games}[1]->last_played;
$user->store();
break;
The first field, cb_lastactive is a DATE field.
The second field, cb_lastplayeddate is a TEXT field.

when the code runs as is, cb_lastactive displays 22/20/9 for the date. cb_lastplayeddate displays 9/22/2011.
variable $data->{recent_games}[1]->last_played is a string, which is why I tried
$resultDate = strtotime($data->{recent_games}[1]->last_played); which will allow the field to be updated in the BROWSER, but the $user->store(); doesn't work. I can't get anything into that date field using that function. HELP!

Please Log in or Create an account to join the conversation.

13 years 3 weeks ago - 13 years 3 weeks ago #177398 by busterocaps
Replied by busterocaps on topic Re: string to date field
figured it out, for anyone else that may run in to this issue. For whatever reason, a date STRING is in the wrong order for CB to accept it into a DATE FIELD. So you have to explode it first, then reconstruct it in a format CB will take.
Code:
//String is contained in an array, in MM/DD/YYYY format ie 09/22/2011 // exploding puts the string into an array, [0] is 09, [1] is 22, [2] is 2011 $date = explode("/", $data->{recent_games}[1]->last_played); // Rearrange them to CB liking $dateformat= ($date[2]."/"."0".$date[0]."/".$date[1]); //This part posts the properly formatted string to the date field $user->cb_lastactive = $dateformat; $user->store();
Last edit: 13 years 3 weeks ago by busterocaps.

Please Log in or Create an account to join the conversation.

  • nant
  • nant
  • OFFLINE
  • Posts: 12339
  • Thanks: 1467
  • Karma: 877
13 years 3 weeks ago #177423 by nant
Replied by nant on topic Re: string to date field
I don't understand.

Is this your code or some code in CB?

Please Log in or Create an account to join the conversation.

13 years 3 weeks ago #177449 by busterocaps
Replied by busterocaps on topic Re: string to date field
My apologies. if you read the first post you see that I was trying to send a string to a CB date field from some code I had modified in a cb plugin, and I couldn't get it right. I could get the field on the tab to show up, but the DATE field wouldn't save until I added that code in the second post. After a lot of trial and error I finally got it to go in there but I had to jack it around to do it. I have no idea why, so I posted my solution to the problem.

Please Log in or Create an account to join the conversation.

  • nant
  • nant
  • OFFLINE
  • Posts: 12339
  • Thanks: 1467
  • Karma: 877
13 years 3 weeks ago #177451 by nant
Replied by nant on topic Re: string to date field

busterocaps wrote: My apologies. if you read the first post you see that I was trying to send a string to a CB date field from some code I had modified in a cb plugin, and I couldn't get it right. I could get the field on the tab to show up, but the DATE field wouldn't save until I added that code in the second post. After a lot of trial and error I finally got it to go in there but I had to jack it around to do it. I have no idea why, so I posted my solution to the problem.


Thanks for posting.

I was confused because you posted in the potential bug area of CB.

Please Log in or Create an account to join the conversation.

13 years 3 weeks ago #177453 by busterocaps
Replied by busterocaps on topic Re: string to date field
That's what I assumed it was, because I had to change the format of the date around to get the cb date field to accept it.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum