473,394 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

date formating

Hi all,

the following is a chunk of my code:

char timebuf[10];
char datebuf[10];
_strtime( timebuf );
_strdate( datebuf );

cout<<timebuf<<endl; //output: 15:48:59
cout<<datebuf<<endl; //output: 09/14/06

what is the simplest way to format the date to look like 09-14-2006

PS:I have all the necessary libraries included.

Thanks a lot
Sep 14 '06 #1
3 2858
There is no function to change the date to the format you required. Just access the position of colon in the buffer datebuf and change the colon to hyphen.
Sep 15 '06 #2
Ok i just did simple array formatting however it was giving me casting problems when i was jsut trying to do...

datebuf[2] = "-"; // why was this causing the following issue?

error C2440: '=' : cannot convert from 'char [2]' to 'char'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast

Finally i decided to go through ASCII unable to resolve the above problem:

char timebuf[10];
char datebuf[10];
const unsigned char asciiDash(45);
_strtime( timebuf );
_strdate( datebuf );
datebuf[2] = asciiDash;
datebuf[5] = asciiDash;

and got 09-15-06...
Sep 15 '06 #3
See the assignment you are done......

datebuf[2] = "-"; // why was this causing the following issue?


Lefthand side is a character and the right hand side is a string which is of type (char *). So the RHS is not compatible with the LHS. Hence the issue.

See the difference between single quotes and double quotes.

Make the assignment like this.....

datebuf[2] = '-';
Sep 15 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tony | last post by:
Hello everyone, Okay so here is my pickle! I have a field called ARCH_DATE within a table which has a date stored like "9/1/2004 23:50:00". What I would like to do is create a date range which...
1
by: JAPHET | last post by:
I am Trying to Format date in my Datagrid to SHORTDATE format with the following codes, Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As...
12
by: Rob Meade | last post by:
Hi all, Ok - I've come from a 1.1 background - and previously I've never had any problem with doing this: Response.Write (Session("MyDate").ToString("dd/MM/yyyy")) So, I might get this for...
3
uranuskid
by: uranuskid | last post by:
Hey folks, I have aliile issue with my Date. I query the data base with a comperative query (see below) and want to get the date in a different format. At first the query: $query =...
7
by: bdbeames | last post by:
I never used Perl before, so I need a little help formating a date. What I'm doing is querying a postgres database and then creating a .xml file for a RSS feed. I don't know how to correctly format...
2
by: jacc14 | last post by:
Hi Hope there is someone out there that can help. I am sure this is an easy one although not easy to explain. I have a form which produces a report using a query. On the form I have a start and...
5
by: cmdolcet69 | last post by:
How can i format a Julian day and only the single digit in the year. I only wnat the julian day and the last digit of the year (7) For example the code below i thought would do this however i...
9
by: TC | last post by:
Hi. I have some ASP written in VB.net which is currently installed on a customers server. The asp connects to a local MySql database and retrieves data for the customers customers. If you see...
6
by: Geoff Cox | last post by:
Hello, at the moment I can add the combined date and time into MySQL using php $dt1 = date("Y-m-d H:i:s"); is it possible to add the date and time separately? I thought it might be
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.