Jump to content

Recommended Posts

hello people.

 

i have 2 questions :

 

-how to save a date from a html form in mysql database in the dd-mm-yyyy format ?!

 

- i have a website with users being able to publish their concerts. I wish to SHOW in php all the concerts that are about to be HELD, and all concerts that have passed, i would like them to be not showns... is it possible ??

 

thanks in advance..

 

Link to comment
https://forums.phpfreaks.com/topic/150122-mysql-date-format/
Share on other sites

Right, well in reply to your first question you can get the date by doing something like this:

 

$date = date('d/m/Y', time());

 

And your second question, do something like this:

 

<?php
$limit = 60 * 60 * 24 * 7; //seven days
mysql_query("SELECT * FROM table WHERE date <= '$limit'"); //select from the table where the date held is less than or equal to the limit
?>

Link to comment
https://forums.phpfreaks.com/topic/150122-mysql-date-format/#findComment-788373
Share on other sites

hmmm here is my code :

 

$date = date("d-m-y");

then i put it in database , and it comes in this format : 2020-03-09 !!!!

 

it is for sure not the right time..what is happening ??

 

p.s.

my table structure is : type = date, default = 0000-00-00 ....i cant change it...

 

Link to comment
https://forums.phpfreaks.com/topic/150122-mysql-date-format/#findComment-788393
Share on other sites

hello guys,

 

i used this  :

echo date("d.m.Y",strtotime("$comment_date"));

 

and in the echo i can decide how to OUTPUT the date....simple as that... :)

 

do you guys know what is the BEST way to store lets say a birthday date in database through a html form ?

just looking for an advice :)

Link to comment
https://forums.phpfreaks.com/topic/150122-mysql-date-format/#findComment-788473
Share on other sites

Hrmmm, nothing since a unix timestamp can be converted to a DATE.

 

 

Why have the overhead of conversion though?

 

 

 

A lot of stuff requires conversion by the way.  Yeah, you can order a unix timestamp, and yeah, you can do ranges calculated in PHP, but some stuff would be too ghetto to do that way.

Link to comment
https://forums.phpfreaks.com/topic/150122-mysql-date-format/#findComment-788991
Share on other sites

That was my point to your comment.  There is nothing you can do with Unix Timestamp that you can't do with a MySQL Date/Time.  And as pointed out, goes beyond dates before 1970.

 

...why?

 

What can you do with a date that you can't do with a timestamp..?

Link to comment
https://forums.phpfreaks.com/topic/150122-mysql-date-format/#findComment-789435
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.