Jump to content

What is the best way to compare dates with SQL


cjbeck71081

Recommended Posts

I was wondering what you guys do to prepare dates for SQL, and then when they come out of SQL how to prepare them for analysis.  I have always been pulling dates together using a string, and then poping them into SQL, and when they come out of SQL i have been decoding them... i'm sure there is a better way.

 

In other words... someone signs up for something, i want to time stamp thier sign up.  I would populate the now(); date into the sql, but i want to make sure its in "DATE" format to fit my SQL syntaxt.  And if i wanted to send them an email with the date they signed up, I would format it to read "January 15th 1980".  Without hacking it up.

 

Thanks in advance

Chris

Link to comment
Share on other sites

Thanks for your reply, im looking now, i found a nice way to insert into SQL the current date.  But now, coming out of SQL the format is 2008-08-09.  Again, I know i can hack it, but im looking for the most straight forward way to either rearrange the numbers to read 08-09-2008 or convert them altogether and say August 09, 2008.

 

I'll look at strtoday and mktime.

Link to comment
Share on other sites

the most straight forward way I've ever used is the UNIX timestamp..

as cooldude mentioned..PHP has functions to manipulate these timestamps in sooooo many ways..with no hacking

 

also,......mysql has functions to play with them as well.

 

 

 

When I populated echo(date("F j, Y", $date));

 

It gave me December 31, 1969.  Any ideas?

date works the UNIX timestamp.

CURDATE does not return a UNIX timestamp.. it returns a 2008-06-13 type date...

 

the reason it's giving you that mundane date (december 1969) is because you need to convert the 2008-06-13 to a UNIX timestamp with strtotime first before it will work.

 

Why did it give you that exact date?....because um..

UNIX timestamp only go as far back as Jan 1 1970.  and the number you gave it was less than a regular normal......datestamp

 

I hope I answered thoroughly enough

Link to comment
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.