Does Mysql support Ethiopian calendar/ Ethiopian date time - mysql

Is there any concept in mysql to localize the Date time function. I need Date time to be in Ethiopian format. Or atleast a mysql conversion function that displays datetime with respect to Ethiopian Date time.

No, you can not. In MySQL, proleptic Gregorian calendar is used - and there are no other formats. That means there are no native ways to produce such conversions.
However, you can create your own output conversion. To do this, you will need to know both calendars. There are good on-line convertors which you can use to get some examples. So you will store your dates in Gregorian (i.e. MySQL internal) format, but convert them in your application like you need.

MySQL does not a conversion function for ethiopic calendar.
The most straightforward approach would be to create a date table that contains gregorian date on one column and ethiopian on the next, allowing you to easily join it on a standard date to get your ethiopian date.

It doesn't support Ethiopian calendar but you can convert Gregorian date to Ethiopic by creating mysql function and also you can customize it for other database and other programming language.
This is the GitHub link click here

Related

Check if a given date is in Day Light Savings or Not in Mysql

I would like to know if the data in the columns (below) are in Daylight Savings or not
Column names : Start date , End date
As stated, your question fails to acknowledge that there are a lot of different definitions of Daylight Savings time. I wish I could find the article -- there was a great interview with the original maintainers of the DST tables about how they were actually taking guesses in many parts of the world.
The timezone package in Debian and others defines many of these rules to the best ability of the given authorities.
My advice: convert all dates to a known timezone using authoritative tools (UTC is the typical case; or secondary your local time zone), and do all your calculations based on that, without trying to understand the 120+ different timezone definitions.
If you really want to know if a given date is in a DST situation, I would convert the date to a given timezone, format it with a DST extension (e.g. MDT/MST for Mountain Daylight Time or Mountain Standard Time) and look for the MDT/MST suffix to determine daylight-ness. You'll have to define which locale you want daylight-ness, however as the cutoff day varies from locale to locale.

How to store DATE/TIME/YEAR in MySQL DATETIME field?

Sorry if this question has been asked before. I can't seem to find an answer.
MySQL has these types of date/time types:
DATE: 0000-00-00
TIME: 00:00:00
DATETIME: 0000-00-00 00:00:00
TIMESTAMP: 0000-00-00 00:00:00
YEAR: 0000
I know one can use each of these datatypes to store each of them.
How can I store TIME only such as business opening/closing hours,YEAR only such as company year founded and DATE only such as date of birth within a DATETIME field? Thanks.
PS: Am using PHP, if that helps, though am looking for a pure MySQL solution.
I would argue that you should store all of these as datetime. Hours of business can vary based on the day, and you may also need the day or month when a company was founded.
By storing everything as datetime it is possible that you would be persisting extra information. But it would always be possible to easily retrieve the information of interest. For example, to get the year a company was founded you could use either YEAR(date_founded), or if you are feeling more sophisticated you could use DATE_FORMAT('date_founded', '%Y').
What you can do is store timestamp and then use timestamp to get whatever information you want to retrieve from timestamp
Based on language you are using there are available functions to help you with your implementation.
Share the language you are using so we can help you better

MongoDB: should I use string instead of date?

In my web project using angular, node and mongodb with JSON, date is not natively supported by JSON serializer. There is a workaround for this problem, as shown here. However, I wonder what's the benefit saving the date as a date object instead of a string in MongoDB? I'm not that far with the project so I don't see the difference.
By saving your dates not as dates but as strings, you are missing out on some very useful features:
MongoDB can query date-ranges with $gt and $lt.
In version 3.0, the aggregation framework got many useful aggregation operators for date handling. None of those work on strings and few of them can be adequately substituted by string operators.
MongoDB dates are internally handled in UNIX epoch, so nasty details like saving timestamps from different timezones or daylight saving times are a non-issue.
A BSON Date is just 8 byte. A date in the minimal form of YYYYMMDD is 12 byte (strings in BSON are prefixed with a 4 byte integer for the length). When you store it as an ISODate string which uses all the ISO 8601 standard has to offer (date, time accurate to millisecond and timezone), you have 32 byte - four times the storage space.
You need to know if any of this matters for your project.
When you really want to avoid using the BSON Date type, you should consider to store your dates as a number representing the elapsed milliseconds/seconds/hours/days (whatever appropriate for your use-case) since a fixed point in time instead of a string. That way you retain the advantages of everything but point 2.
You should at least use ISO dates if you go for this approach. I would however argue that there are benefits in storing date values as date objects. Storing dates as date objects will allow you to add indices and should also help with date range queries. Saying this many developers seem to be happy to store dates as strings, see What is the best way to store dates in MongoDB?

What is a good alternative to Unix time for encoding date of birth?

I would like to use unix time for date of birth, but it doesn't work so well for date of birth because Unix time starts in 1970.
I'll be sending the date of birth as JSON. Does it make sense to use Unix time with negative numbers? Or is there another standard that works better?
This is for an API, working with multiple clients, so I want to use a standard, simple convention. YYYYMMDD seems confusing and error prone.
The International Organization for Standardization (ISO) advocates YYYY-MM-DD.
The World Wide Web Consortium (W3C)'s Quality Assurance Interest Group (QAIG) comments:
Albeit not perfect, ISO date format is, however, the best choice for a date representation that is universally (and accurately) understandable. [link]
And I think most technically-minded people will recognize it.

Best way store a date/time for different timezones

What's the best way to store timezone information with dates/times in a uniform way so people can enter times from anywhere in the world in their own local time? Other users would then have the ability to view the times in their own local time and the original localtime on the web page.
Store the time data as GMT. Display it using local time. This requires a simple offset from GMT. Now if the politicians would leave the starting and end date for Day light savings time alone...
I'd agree with Staale, but add that times should be stored in Zulu time (commonly called UTC), to make for easier translation into other timezones. Don't rely on storing data in the timezone used by your server.
I would suggest inserting the date in UTC time zone. This will save you a lot of headache in the future (Daylight saving problems etc...)
"INSERT INTO abc_table (registrationtime) VALUES (UTC_TIMESTAMP())"
When I query my data I use the following PHP script
<? while($row = mysql_fetch_array($registration)){
$dt_obj = new DateTime($row['message_sent_timestamp']." UTC");
$dt_obj->setTimezone(new DateTimeZone('Europe/Istanbul'));
echo $formatted_date_long=date_format($dt_obj, 'Y-m-d H:i:s'); } ?>
You can replace the datetimezone value with one of the available php timezones here:
My view has always been to store exact numeric timestamps (seconds or milliseconds since midnight 1st january 1970 GMT), as that's a format that is easily converted to an actual date and time in any timezone.
The downside of this is that the data isn't as immediately viewable through normal SQL tools. The mysql cli client does have methods for this though (FROM_UNIXTIMESTAMP).
Always store as times as UTC/GMT. Check the mysql docs to see what column type is best for the range of dates and/or precision that you want to support.
On input, convert to UTC and store the client timezone offset in a second column. Then you can easily convert to any timezone you want for display, or use the submitted offset to recreate the original timestamp.