Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 18th, 2008, 11:11 PM   #1
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 256
Rep Power: 2 Jabo is on a distinguished road
Command line date math

Can anyone point me somewhere or help me with date manipulation from a command prompt. I've searched for a couple of days and I'm not finding anything helpful. What I'm trying to do is manipulate the %date% to reflect the day before. I've tried %date-1:~7,2%, %date:~7,2%-1, %date:~7,2,-1%.

I'm taking it this is not possible, and the value will have to be put into a variable before I can manipulate it. Thing is, this means I'm going to have to put in a whole slew of date checking programming to make sure the date is valid just to do a simple batch file. If anybody has a tip or website, please let me know.

This is for a WinXP machine btw

Last edited by Jabo; Apr 18th, 2008 at 11:34 PM.
Jabo is offline   Reply With Quote
Old Apr 18th, 2008, 11:57 PM   #2
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,009
Rep Power: 5 lectricpharaoh will become famous soon enough
Re: Command line date math

What exactly is it you need this for? It sounds to me like you will need to use an actual programming language; using (for example) C# makes it pretty easy:
C# Syntax (Toggle Plain Text)
  1. DateTime yesterday = DateTime.Today.AddDays(-1.0);
You can then use the Day, Month, etc properties to get the actual information you need. It's extremely simple. In fact, I think the hardest part will be getting the information to your batch file, though piping or using the errorlevel may serve the purpose.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Apr 19th, 2008, 12:32 AM   #3
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 256
Rep Power: 2 Jabo is on a distinguished road
Re: Command line date math

Actually, getting the information to my batch file is easy using echo to create an FTP script file. Every day we have data generated on our servers, and some of this information is generated for the day before. What I'm doing is grabbing the files and moving them to a backup location, but so far I've only been able to create batch files that grab the files for today's date, not yesterday's. The date is in the file names, and I'm trying to create a script from within my batch file to get those files with yesterday's date, but the %date% function doesn't seem to want to do date math, in other words, %date-1% or whatever. It should be easy to do this with a programming language, but I've read there is very little you can't do from the command line that you can do from a programming language. So, therefor, if it can be done with command line, I'm all for it.

Besides, I've tried to start a program that does FTP, and it's pretty complicated from what I've read about it in VB 2005. Not as simple as using the FTP that is included in windows. I don't want to create a complete FTP just to do a simple task that might go away in a week or a month.

EDIT: I guess I could use a shell command to do the FTP part and then do the math in a VB program, then another shell FTP to move the files to the destination.
Jabo is offline   Reply With Quote
Old Apr 19th, 2008, 1:30 AM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Re: Command line date math

Why use a batch file when you could use all manner of other scripting languages and compile them into an EXE, which can be run anywhere?

You can do a lot of complicated stuff with a batch file. Whether it's worth doing, I'm not so sure. Even Microsoft seem to have abandoned the idea with the Windows PowerShell.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Apr 19th, 2008, 5:49 AM   #5
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 256
Rep Power: 2 Jabo is on a distinguished road
Re: Command line date math

It's gonna take some time for me to learn scripting; in the mean time, I am doing batches.
Jabo is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with Date objects sackarias Visual Basic .NET 2 Jan 9th, 2008 12:46 PM
Date Routine tbohon Perl 2 Jan 15th, 2007 11:14 AM
Computer Science Prereqs - Math bigguy Coder's Corner Lounge 22 Mar 15th, 2006 12:19 AM
Math Games Sane Coder's Corner Lounge 8 Dec 22nd, 2005 3:30 AM
Recommended math book to accompany course? Jessehk Coder's Corner Lounge 7 Nov 15th, 2005 6:05 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:09 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC