PDA

View Full Version : Switch Case



NancyJ
06-30-2007, 01:48 AM
I have a switch statement and its probably not possible to do what I want to do but I thought I'd ask...

I have 2 similar cases (date and datetime)
so if its date or datetime I want to show the date, then after that only put the time if its datetime.

Now if I wanted the time to go first, it would be easy... but the time has to go at the end not the beginning.

pr0gr4mm3r
06-30-2007, 01:52 AM
Are your date and datetime values in the UNIX timestamp format?

PappaJohn
06-30-2007, 04:14 AM
switch ($var_name)
{
case 'date':
case 'datetime':
// display date

if ( $var_name == 'datetime' )
{
// display time
}

break;
}

whizard
06-30-2007, 04:17 AM
Wouldn't just



//display date (regardless)
if($var_name == 'datetime' )
{
// display time
}

work?

Dan

NancyJ
06-30-2007, 09:44 AM
Must hve been late, didnt think of just stick and 'if' in there. Still seems so inelegant :(

Wouldn't just



//display date (regardless)
if($var_name == 'datetime' )
{
// display time
}

work?

Dan
Date and datetime are not the only cases, so no.

Fumigator
06-30-2007, 10:49 PM
Inelegant shouldn't be more important than "it works" :p

firepages
07-01-2007, 05:31 AM
I don't get it .. what's wrong with this ??


<?php
switch($var){
case 'date': echo $date; break
case 'datetime' : echo $date;
echo $time; break;
}
?>

PappaJohn
07-01-2007, 05:53 AM
I'm assuming it's more complex than just outputting date & time. I use this technique often when 2 (or more) cases share a good bit of code. For example, when building output, several cases may output data in the same format with just the variable information changing.