/    Sign up×
Community /Pin to ProfileBookmark

php mysql time value

Hi

I want to sent a time value from avariable to a mysql database. the column in mysql wil be formated as time. I have the following information that is being based from a form that I want to enter into the mysql database. My question is how do I format t the values be for sending them

$startHr = $_POST[‘startHr’];
$startMin = $_
POST[‘startMin’];
$startAmPm = $_POST[‘startAmPm’];

I want to create a variable $startTime that I can use to pass the time to the database. I will write a If statement to convert the time to a military time.

any help is great

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 08.2009 — Assuming $startHr will be an integer from 1-12 and $startAmPm will be either "AM" or "PM", You could do:
[code=php]
if($startAmPm == "PM")
{
$startHr += 12;
}
if($startHr == 12 and $startAmPm == "AM")
{
$startHr = 0;
}
$dbTime = sprintf("%02d:%02d", $startHr, $startMin);
[/code]
×

Success!

Help @kproc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.14,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...