FREE PLUGIN: DATETIME Manipualtion

DATETIME ManipulationDATETIME Manipulation plugin will make your life easier when dealing with any kind of date/time format/language. It allows you to convert any date/time to any other format, including conversion from one language/culture to another. For easy of use plugin supports UBOT standard date and time format “$date”, UNIX time-stamp and a few other standard date/time formats.

This plugin will add one new UBot function to your UBot environment, and  the function is called $datetime manipulation. Once its ran it will recognize the input date and/or time (specified by Input Format parameter), and it will convert it into a custom date and/or time format (specified by “Output Format”).

FUNCTION: $datetime manipulation

Function $datetime manipulation allows you to convert any Date and/or Time to any other format, you only need to specify the right “Input Format” parameter, so that the Input Date/Time gets recognized. In addition you can also change Input/Output cultures, which allows you to to convert date and/or time between different cultures/languages (for example from “en_US” to “de_DE” ).

DATETIME Format Parameters

Custom Format And Standard TimesParameters “Input Format” and “Output Format” are drop-downs, containing values for time formats UBOT, UNIX, and a few others for standard format like general date/time, short/long date, full date/time (short/long time), sortable date/time, Universal sortable date/time,….

By defining the parameter “Input Format” you tell the function in which format the “Input Date/Time parameter is provided, and similarly for “Output Format” parameter, where you specify in which format “Output Date/Time should be. Both of the format parameters mentioned above are drop-downs, but they also accept custom values, allowing you to format your own custom DATETIME.

 

Standard Format Date/Times (Drop-down)

Bellow you can find examples of all standard date/time formats available from “Input Format” and “Output Format” drop-downs:

Standard FormatExamples
Standard FormatExamples
UBOT06.15.2009 13:45:30 (always in this format, no matter where the computer is or what's the culture)
UNIX1245073530 (universal time based on UTC)
Full date/time (long time)Monday, June 15, 2009 1:45:30 PM (en-US)
Montag, 15. Juni 2009 13:45:30 (de-DE)
Full date/time (short time)Monday, June 15, 2009 1:45 PM (en-US)
Montag, 15. Juni 2009 13:45 (de-DE)
General date/time (long time)6/15/2009 1:45:30 PM (en-US)
15.06.2009 13:45:30 (de-DE)
General date/time (short time)6/15/2009 1:45 PM (en-US)
15.06.2009 13:45 (de-DE)
Long dateMonday, June 15, 2009 (en-US)
Montag, 15. Juni 2009 (de-DE)
Long time1:45:30 PM (en-US)
13:45:30 (de-DE)
Month/dayJune 15 (en-US)
15 Juni (de-DE)
RFC1123Mon, 15 Jun 2009 20:45:30 GMT (en-US)
Mon, 15 Jun 2009 13:45:30 GMT (de-DE)
Round-trip date/time2009-06-15T13:45:30.0900000 (en-US)
2009-06-15T13:45:30.0900000 (de-DE)
Short date6/15/2009 (en-US)
15/06/2009 (de-DE)
Short time1:45 PM (en-US)
13:45 (de-DE)
Sortable date/time2009-06-15T13:45:30 (en-US)
2009-06-15T13:45:30 (de-DE)
Universal full date/timeMonday, June 15, 2009 8:45:30 PM (en-US)
Montag, 15. Juni 2009 11:45:30 (de-DE)
Universal sortable date/time2009-06-15 20:45:30Z (en-US)
2009-06-15 13:45:30Z (de-DE)
Year monthJune, 2009 (en-US)
Juni 2009 (de-DE)

Notice that culture has effect on most of the dates/times above.

 

Custom Format Specifiers:

If standard date/time formats from drop-down won’t suit you, you can also specify a custom format using format specifiers, which will allow you to format input/output date/time in any way you like. In order to achieve that, you need to provide a string consisting of custom format specifiers, by manually entering the values for parameters “Input Format” and “Output Format” (ignore the drop-down, just enter the string).

For example we would describe UBOT DATETIME format with a string “MM\\/dd\\/yyyy HH\\:mm\\:ss“.

You can find most commonly used “format specifiers” in the table bellow:

Format SpecifierDescription
Format SpecifierDescription
dThe day of the month, from 1 through 31.
ddThe day of the month, from 01 through 31.
dddThe abbreviated name of the day of the week.
gThe period.
ggThe era.
hThe hour, using a 12-hour clock from 1 to 12.
hhThe hour, using a 12-hour clock from 01 to 12.
HThe hour, using a 24-hour clock from 0 to 23.
mThe minute, from 0 through 59.
mmThe minute, from 00 through 59.
MThe month, from 1 through 12.
MMThe month, from 01 through 12.
MMMThe abbreviated name of the month.
MMMMThe full name of the month.
sThe second, from 0 through 59.
ssThe second, from 00 through 59.
tThe first character of the AM/PM designator.
ttThe AM/PM designator.
yThe year, from 0 to 99.
yyThe year, from 00 to 99.
yyyThe year, with a minimum of three digits.
yyyyyThe year as a five-digit number.
zHours offset from UTC, with no leading zeros.
zzHours offset from UTC, with a leading zero for a single-digit value.
zzzHours and minutes offset from UTC.
:The time separator.
/The date separator.
"string"Literal string delimiter.

Function also supports some additional “format specifiers”, and you can find more about them here.

DATETIME Culture Parameters

Input Culture” and “Output Culture” are drop-downs which include different cultures/languages, and they allow you to specify which culture/language should be used when recognizing the “Input Date/Time” and when generating Output Date/Time (no custom entry allowed here).

Impact on Standard and Custom Formats

By using custom date/time format, culture only has impact on language and date/time delimiters (if used), since the format itself is defined by the order of custom format specifiers inside a formatting string. In case where one of the standard dates/times from drop-down is used, culture will have impact on format and language, since different countries/cultures use different formatting for date/time.

Culture doesn’t have impact on UBOT and UNIX formats, as well as it doesn’t effect some other standard dates/times which have predefined format (like Universal Time for example).

NOTES

Convert Between Different Time Zones

Function can also be used to convert time from different UTC offsets, but it will always return your local offset. You should also know that it’s not recommended to use parameter “z” in DATETIME, since this is not a standard format for DATETIME (but it will allow you conversion).

Converting DATE or TIME only

If TIME part of input parameter is not provided or the TIME is provided insufficiently (e.g. hour is missing), the missing values will be set to 0. If DATE part is missing or is provided insufficiently, function will use today’s date.

 

UBOT CODE EXAMPLES

Compare two UNIX timestamps to get time difference

DATETIME UNIX Timestamp UsageBy converting DATETIME from UBOT (“$date” function) to UNIX Timestamp, we get the number of seconds passed since 1/1/1970, which makes UNIX format easy for time comparison.

To get number of seconds passed from one event to another, we just need to convert both times into UNIX format and subtract the older date from the newer one (NEWER-OLDER), and the result is number of seconds that passed during those 2 events.

 

Convert to a custom DATE TIME

DATETIME Custom Format ExampleSometimes you may need a special format for date/time, and with this function you can  format it however you want.

If we refer to image on the left, we can see that Input Date/Time is set to “Fri, Mar 03/01/2013 10:11:12 AM“, and its described with Input Formatddd, MMM MM/dd/yyyy hh:mm:ss tt”, with format specifiers explained bellow:

      • “ddd” – The abbreviated name of the day of the week.
      • “MMM” – The abbreviated name of the month.
      • “MM” – The month, from 01 through 12.
      • “/” – “The date separator.”
      • “dd” – The day of the month, from 01 through 31.
      • “yyyy” – The year as a four-digit number.
      • “hh” – The hour, using a 12-hour clock from 01 to 12.
      • “mm” – The minute, from 00 through 59.
      • “ss” – The second, from 00 through 59.
      • “tt” – The AM/PM designator.

We also have to specify output format, which in this set to: “DateTime was:” dddd – MMMM – dd/MM/yy HH:mm:ss g“, and the format specifiers used are explained bellow:

  • “dddd” – The full name of the day of the week.
  • “MMMM” – The full name of the month.
  • dd” – The day of the month, from 01 through 31.
  • “/” – “The date separator.”
  • “MM” – The month, from 01 through 12.
  • “yy” – The year, from 00 to 99.
  • “HH” – The hour, using a 24-hour clock from 00 to 23.
  • “mm” – The minute, from 00 through 59.
  • “ss” – The second, from 00 through 59.
  • “g” – The period

ADDITIONAL READING

 

UPDATE v1.01

Integer To Time Span

I’ve added a new function called “$datetime time span” which will convert an integer (for example number of seconds) to a more human-readable format – time span ( for example number “12345678” (seconds) would get converted to “142d:21h:21:18s” when using default settings. There are some other options which are quite self explanatory, so I won’t be describing them here.

UBOT FORUM DISCUSSION

[FREE PLUGIN] DATETIME Manipulation

 

DOWNLOAD

DOWNLOAD FREE PLUGINS

If you like this FREE UBot Plugin or find the post useful, please consider leaving a comment bellow or sharing it on your favorite social network.

5 thoughts on “FREE PLUGIN: DATETIME Manipualtion

    1. Tadej UBotDev Post author

      Sorry for extremely late reply, wasn’t much around. Website broke because one of the plugins went missing (working on it).

      You can always download all of the plugins by subscribing here.

      Reply
    1. Tadej UBotDev Post author

      Sorry for late reply. Website wasn’t managed for a year and something broke download button.

      You can download all of the plugins by subscribing here.

      Reply
  1. Tadej UBotDev Post author

    PRO Tip 🙂 and a reminder for myself: Use singe quote if you wan’t to display protected characters…for displaying “2017-03-22 @ 20h” one needs to use “yyyy-MM-dd @ HH’h'” (without double quotes).

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*