CodeCogs - An iteractive open source Numerical library Welcome... Login
CodeCogs
shopping cart
OSXWindowsLinux
Search CodeCogs
Numerical Components

Valid RSS

UnitsDate

date str

Only available under a commercial licence
COST (GBP)
this unit 0.00
sub units 32.98
add a commercial licence to your cart
0
viewed 3878 times and licensed 5 times

Returns a date formatted according to a given format string.

Further Info Controller: CodeCogs  Contact Controller
+View version details
Contents hide toc
buy now     add cart

Interface

#include <codecogs/units/date/date_str.h>

using namespace Units::Date;

char* date_str (char* Format, double Date=-1)
Returns a date formatted according to a given format string.
ExcelString cc_date_str (String Format, Real Date)
This function is available as a Microsoft Excel add-in.

Function Documentation

 
char*date_strchar*Format
doubleDate = -1 )
Returns a string formatted according to the given format string using the given integer timestamp or the current local time if no timestamp is given.

Fills the string based on the given format, date and region

For convenience, the format characters have been arranged by category.

Year format specifiers
Option Description Examples
L Whether it's a leap year. 1 if it is a leap year, 0 otherwise.
Y A full numeric representation of a year, 4 digits. If needed, BC will be suffixed. 4713BC, 1999, 2005
y A two digit representation of a year. If needed, BC will be suffixed. 13BC, 99 or 05

Month format specifiers
Option Description Examples
F A full textual representation of a month. Jan through Dec
m Numeric representation of a month, with leading zeros. 01 through 12
M A short textual representation of a month consisting of three letters. Jan through Dec
n Numeric representation of a month, without leading zeros. 1 through 12
t Number of days in the given month. 28 through 31

Day format specifiers
Option Description Examples
d Day of the month, 2 digits with leading zeros. 01 through 31
j Day of the month without leading zeros. 1 through 31
S English ordinal suffix for the day of the month, 2 characters. Works well with j st, nd, rd or th
z The day of the year (starting from 0). 0 through 365

Week format specifiers
Option Description Examples
D A textual representation of a day, three letters. Sun through Sat
l (lowercase 'L') A full textual representation of the day of the week. Sunday through Saturday
w Numeric representation of the day of the week. 0 (for Sunday) through 6 (for Saturday)
W ISO-8601 week number of year, weeks starting on Monday. 42

Time format specifiers
Option Description Examples
a Lowercase Ante meridiem and Post meridiem am or pm
A Uppercase Ante meridiem and Post meridiem AM or PM
B Swatch Internet time 000 through 999
g 12-hour format of an hour without leading zeros. 1 through 12
G 24-hour format of an hour without leading zeros. 0 through 23
h 12-hour format of an hour with leading zeros 01 through 12
H 24-hour format of an hour with leading zeros. 00 through 23
i Minutes with leading zeros. 00 to 59
s Seconds, with leading zeros. 00 through 59
U Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) 1112053296

Timezone related specifiers
Option Description Examples
I (uppercase 'i') Whether or not the date is in daylights savings time. 1 if Daylight Savings Time, 0 otherwise.
O Difference to Greenwich time (GMT) in hours. +0200 , -1300
T Timezone setting of this machine. EST, MDT
Z Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. -43200 through 43200

Standard format specifiers
Option Description Examples
c ISO 8601 date 2005-03-29T00:47:51+0100
r RFC 2822 formatted date Tue, 29 Mar 2005 00:47:51 +0100
Parameters:
formatConstant
dt[in] The date and time to use
region[in] The current region
Authors:
Keith Athaide
Warning:
The string returned by this function is dynamically allocated and it is necessary for the calling code to deallocate it with a delete statement otherwise a memory leak will occur.

Example

#include <iostream>
#include <codecogs/units/date/date_str.h>
 
int main()
{
  char* pDateStr = Units::Date::date_str("l dS of F Y h:i:s A");
  std::cout<<pDateStr;
  delete[] pDateStr;
  return 0;
}
Output:
Tuesday 29th of March 2005 03:27:48 AM

Example 2

Any of the format string examples shown above can be used. Additionally a timestamp could be specified.
#include <iostream>
#include <codecogs/units/date/date_str.h>
 
int main()
{
  char* pDateStr = Units::Date::date_str("j, n, Y ", 2123011);
  std::cout<<pDateStr;
 
  delete[] pDateStr;
  return 0;
}
Output:
4, 7, 1100
Parameters:
DateDefault Value = -1)
Returns:
The formatted string
Authors:
Keith Athaide
Source Code:

To view or download source code you need to buy a Commercial licence.

buy now     add cart

Not a member, then Register with CodeCogs. Already a Member, then Login.


Page Comments

Format Excel Equations

  You must login to leave a messge


Last Modified: 18 Oct 07 @ 17:07     Page Rendered: 2010-03-11 15:52:26

Valid CSS!   Valid XHTML 1.0 Transitional