473,320 Members | 2,107 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,320 software developers and data experts.

trimming date

Hi all

I have a string like this "2/6/1986" which is a date..Remember that it is a date actually..so day size and month size are variant..It is not always single digit or single character...
I want "1986","6","2" individually...

Can anybody provide trimming code to do this ..

Thankful to you all,
Apr 7 '09 #1
5 1479
gits
5,390 Expert Mod 4TB
where do you need that? at the clientside you could use javascript like in the following example to achieve it:

Expand|Select|Wrap|Line Numbers
  1. // your value
  2. var val = '2/6/1986';
  3.  
  4. // just split it at the slashes
  5. // to get an array with the separated
  6. // values
  7. var d = val.split('/');
  8.  
  9. // in case you want it reverse orderd
  10. var d = val.split('/').reverse();
  11.  
or do you need a serverside solution? in this case you could have a look here

kind regards
Apr 7 '09 #2
Frinavale
9,735 Expert Mod 8TB
Well it's pretty easy server side too.
You can refer to the properties of the Date Object....
The following will return today's month, day, and year in individual variables:
Expand|Select|Wrap|Line Numbers
  1. Dim month As Integer = Now.Month
  2. Dim day As Integer = Now.Day
  3. Dim year As Integer = Now.Year
Apr 7 '09 #3
Hi boss,
You did not get my actual problem.
I am getting that date from the database and filling in data table.
That data table is stored in session variable.
In the redirected page in page_load i need to trim date,month and year and I need to use like this
ddlDay.Value = trimmed day
ddlMonth.Value = trimmed Month
ddlYear.Value = trimmed Year

Now help me in trimming the date string(code in C#) .Remember that it is a date actually..so day size and month size are variant..It is not always single digit or single character...
Thanking you boss.
Apr 8 '09 #4
gits
5,390 Expert Mod 4TB
do you mean that you just want to know how to make a 2 from '02' ... just cast that string '02' to an integer ... that should be pretty easy?

kind regards
Apr 8 '09 #5
Frinavale
9,735 Expert Mod 8TB
I did miss read. You said that it's a String containing a date...not a Date Object.

Well you could use the String.Split() method...splitting on the '/' character. The Split() method will return an array of Strings. Just like Gits recommended (only you'd use C# instead of JavaScript).

Or you could use the DateTime.Parse() method to parse the string into a DateTime Object and then you will be able to grab the components like I had suggested earlier.

Or you could use Regular Expressions to retrieve the components.


There are many ways to solve this problem.

Give one of them a try and let us know if you're having problems.

-Frinny
Apr 8 '09 #6

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

Similar topics

1
by: Beyonder | last post by:
I'm using InnoDB with Mysql and I've used delete to delete over 10 million records, but the InnoDB database is still the same size on the disk (over 100 gigs) is there a way to get Mysql/InnoDB to...
2
by: Simon | last post by:
Hi there. I seem to be a flurry of questions here recently, thanks for you help all, but ... got another question here. I am storing URL in a database for a 'sort of' directory type website. ...
6
by: Generic Usenet Account | last post by:
I have worked out the following implementation for trimming the leading and trailing whitespace characters of a string (I am surprised not to see these as member functions). Am I doing it...
12
by: Stefan Weiss | last post by:
Hi. (this is somewhat similar to yesterday's thread about empty links) I noticed that Tidy issues warnings whenever it encounters empty tags, and strips those tags if cleanup was requested....
13
by: john_g83 | last post by:
have a bit of c code that is ment to take a string (that may or may not have spaces before or after the string) i.e. " stuff ", and trims off the whitespace before and after. Code: char *trim...
0
by: Paul | last post by:
On my local site, I have a folder that is security trimmed, so that only members of a Role can see it after they register and log on (I set the memberships). All works fine locally. However,...
3
by: leeps_my | last post by:
I'm thinking of using "resize-to-size" to do the trimming: aVector.resize( aVector.size( ) ); I'm wondering why Scott Meyers was recommending "swap trick" instead, since the trick involves...
8
by: PvtPile | last post by:
I've got a form where i need to pull both the directory of a filename and the directory with the filename of an .inf file... I figured the easiest way to do this was to have an <input id=test...
0
by: rmgalante | last post by:
Hi, I've got my site configured to use a menu control, a site map, security trimming, and roles. Everything seems to be working, except I have the following problem. If I define a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.