Skip to content

Instantly share code, notes, and snippets.

@atishgoswami
Last active December 17, 2015 02:19
Show Gist options
  • Save atishgoswami/5534672 to your computer and use it in GitHub Desktop.
Save atishgoswami/5534672 to your computer and use it in GitHub Desktop.
SQL Conditional Field Query
<?php
$conditionalField
= '(IF( User.joined_date IS NOT NULL,
DATE_FORMAT(User.joined_date, "%d-%m"),
DATE_FORMAT(User.created, "%d-%m")))';
$conditionalField2
= '(IF( User.joined_date IS NOT NULL,
DATE_FORMAT(User.joined_date, "%Y"),
DATE_FORMAT(User.created, "%Y")))';
$this->User->recursive = -1;
$flag = true;
$options['conditions'] = array(
$conditionalField => $presentDate,
$conditionalField2.' <'=> date('Y'),
'User.company_id' => AuthComponent::user('company_id'),
'User.account_status' => $userInstance::ACTIVE,
);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment