Jump to content

Recommended Posts

I have a date field that I insert dates into in my mysql database. The default is 0000-00-00, when I insert the date I insert it as variablename with the values as variablenameY-variablenamem-variablenamed. That's all fine, but when I got to edit it as it is y-m-d as is expected. However I want to be able to edit it from a drop down (which is how I add that dates, from a dropdown). So what I need to figure out is how to extract the values from the field after they are inserted. Hope that makes sense. Thanks in advance.
Link to comment
https://forums.phpfreaks.com/topic/15748-working-with-dates/
Share on other sites

Alright here is an example of how I would add it:

[code]
$connection = mysql_connect("$server","$user","$password");
mysql_select_db ($database);

$dateY = $_POST['dateY'];
$datem = $_POST['datem'];
$dated = $_POST['dated'];

$query = "INSERT INTO users(date)  VALUES('$dateY-$datem-$dated');"
[/code]

Then I would make a form that has three dropdown fields. One being for the dateY (year), second being for datem (month), and the third being for dated (day). Then it would insert it into the mysql date field as year-month-day (0000-00-00). So when I go to edit it, I have to edit it in a input field as: 0000-00-00 . I would like to be able to edit it from a dropdown, but I need some way to extract the year-month-day values from the date.
Link to comment
https://forums.phpfreaks.com/topic/15748-working-with-dates/#findComment-64425
Share on other sites

I thought about converting it, but that still doesn't allow me to edit it from a dropdown. Having three different ones: Year, Month, Date. I could just make three different fields in the database, but I've already got a lot added like this so was looking for some ideas before I do that.
Link to comment
https://forums.phpfreaks.com/topic/15748-working-with-dates/#findComment-64426
Share on other sites

It's a fairly simple task, that has little to with dates, but more with strings:

[code]<?php
$res = mysql_query('SELECT date FROM users WHERE user='.$usr) or die ('Query Failed: '.mysql_error())
$row = mysql_fetch_assoc($res);
$arr = explode($row['date'],'-');

$y = $arr[0]; $m = $arr[1]; $y=$arr[2];
?>[/code]

and on from there.
Link to comment
https://forums.phpfreaks.com/topic/15748-working-with-dates/#findComment-64541
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.